public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonOrganizationsConfig config = new AmazonOrganizationsConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonOrganizationsClient client = new AmazonOrganizationsClient(creds, config);

            ListHandshakesForOrganizationResponse resp = new ListHandshakesForOrganizationResponse();

            do
            {
                ListHandshakesForOrganizationRequest req = new ListHandshakesForOrganizationRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.ListHandshakesForOrganization(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.Handshakes)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
Пример #2
0
        /// <summary>
        /// Creates the Organizations client and then calls its
        /// ListAccountsAsync method.
        /// </summary>
        static async Task Main()
        {
            // Create the client object using the default account.
            IAmazonOrganizations client = new AmazonOrganizationsClient();

            var request = new ListAccountsRequest
            {
                MaxResults = 5,
            };

            var response = new ListAccountsResponse();

            try
            {
                do
                {
                    response = await client.ListAccountsAsync(request);

                    response.Accounts.ForEach(a => DisplayAccounts(a));
                    if (response.NextToken is not null)
                    {
                        request.NextToken = response.NextToken;
                    }
                } while (response.NextToken is not null);
            }
            catch (AWSOrganizationsNotInUseException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes the Organizations client object and then uses it to
        /// call the ListOrganizationalUnitsForParentAsync method to retrieve
        /// the list of Organizational Units.
        /// </summary>
        public static async Task Main()
        {
            // Create the client object using the default account.
            IAmazonOrganizations client = new AmazonOrganizationsClient();

            var parentId = "r-sso8";

            var request = new ListOrganizationalUnitsForParentRequest
            {
                ParentId   = parentId,
                MaxResults = 5,
            };

            var response = new ListOrganizationalUnitsForParentResponse();

            try
            {
                do
                {
                    response = await client.ListOrganizationalUnitsForParentAsync(request);

                    response.OrganizationalUnits.ForEach(u => DisplayOrganizationalUnit(u));
                    if (response.NextToken is not null)
                    {
                        request.NextToken = response.NextToken;
                    }
                } while (response.NextToken is not null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #4
0
        /// <summary>
        /// Initializes the Organizations client object and uses it to call
        /// DetachPolicyAsync to detach the policy.
        /// </summary>
        public static async Task Main()
        {
            // Create the client object using the default account.
            IAmazonOrganizations client = new AmazonOrganizationsClient();

            var policyId = "p-c0hsjgmq";
            var targetId = "r-sso8";

            var request = new DetachPolicyRequest
            {
                PolicyId = policyId,
                TargetId = targetId,
            };

            var response = await client.DetachPolicyAsync(request);

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine($"Successfully detached policy with Policy Id: {policyId}.");
            }
            else
            {
                Console.WriteLine("Could not detach the policy.");
            }
        }
Пример #5
0
        /// <summary>
        /// Initializes an Organizations client object and then uses it to call
        /// the CreateOrganizationalUnit method. If the call succeeds, it
        /// displays information about the new Organizational Unit.
        /// </summary>
        public static async Task Main()
        {
            // Create the client object using the default account.
            IAmazonOrganizations client = new AmazonOrganizationsClient();

            var orgUnitName = "ProductDevelopmentUnit";

            var request = new CreateOrganizationalUnitRequest
            {
                Name     = orgUnitName,
                ParentId = "r-sso8",
            };

            var response = await client.CreateOrganizationalUnitAsync(request);

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine($"Successfully created Organizational Unit: {orgUnitName}.");
                Console.WriteLine($"Organizal {orgUnitName} Details");
                Console.WriteLine($"ARN: {response.OrganizationalUnit.Arn} Id: {response.OrganizationalUnit.Id}");
            }
            else
            {
                Console.WriteLine("Could not create new Organizational Unit.");
            }
        }
Пример #6
0
        /// <summary>
        /// Initializes the Amazon Organizations client object uses it to
        /// create a new Organizations Policy, and then displays information
        /// about the newly created Policy.
        /// </summary>
        static async Task Main()
        {
            IAmazonOrganizations client = new AmazonOrganizationsClient();
            var policyContent           = "{" +
                                          "   \"Version\": \"2012-10-17\"," +
                                          "	\"Statement\" : [{" +
                                          "	\"Action\" : [\"s3:*\"]," +
                                          "	\"Effect\" : \"Allow\"," +
                                          "	\"Resource\" : \"*\"" +
                                          "}]" +
                                          "}";

            try
            {
                var response = await client.CreatePolicyAsync(new CreatePolicyRequest
                {
                    Content     = policyContent,
                    Description = "Enables admins of attached accounts to delegate all S3 permissions",
                    Name        = "AllowAllS3Actions",
                    Type        = "SERVICE_CONTROL_POLICY",
                });

                Policy policy = response.Policy;
                Console.WriteLine($"{policy.PolicySummary.Name} has the following content: {policy.Content}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #7
0
        public ListAccountsResponse listAccounts(string nextToken = null)
        {
            AmazonOrganizationsClient client = new AmazonOrganizationsClient();

            ListAccountsRequest request = new ListAccountsRequest()
            {
                NextToken = nextToken
            };
            ListAccountsResponse response = client.ListAccountsAsync(request).Result;

            return(response);
        }
Пример #8
0
        public void OrganizationsCreatePolicy()
        {
            #region to-create-a-service-control-policy

            var client   = new AmazonOrganizationsClient();
            var response = client.CreatePolicy(new CreatePolicyRequest
            {
                Content     = "{\\" Version \ \ ":\\" 2012 - 10 - 17 \ \ ",\\" Statement \ \ ":{\\" Effect \ \ ":\\" Allow \ \ ",\\" Action \ \ ":\\" s3: *\ \ "}}",
                Description = "Enables admins of attached accounts to delegate all S3 permissions",
                Name        = "AllowAllS3Actions",
                Type        = "SERVICE_CONTROL_POLICY"
            });
Пример #9
0
        /// <summary>
        /// Create an Orginizations client object and then uses it to create
        /// a new Organization with the default user as the administrator, and
        /// then displays information about the new organization.
        /// </summary>
        public static async Task Main()
        {
            IAmazonOrganizations client = new AmazonOrganizationsClient();

            var response = await client.CreateOrganizationAsync(new CreateOrganizationRequest
            {
                FeatureSet = "ALL",
            });

            Organization newOrg = response.Organization;

            Console.WriteLine($"Organization: {newOrg.Id} Main Accoount: {newOrg.MasterAccountId}");
        }
Пример #10
0
        public void OrganizationsCreateOrganization()
        {
            #region to-create-a-new-organization-with-all-features enabled

            var client   = new AmazonOrganizationsClient();
            var response = client.CreateOrganization(new CreateOrganizationRequest
            {
            });

            Organization organization = response.Organization;

            #endregion
        }
        protected IAmazonOrganizations CreateClient(AWSCredentials credentials, RegionEndpoint region)
        {
            var config = new AmazonOrganizationsConfig {
                RegionEndpoint = region
            };

            Amazon.PowerShell.Utils.Common.PopulateConfig(this, config);
            this.CustomizeClientConfig(config);
            var client = new AmazonOrganizationsClient(credentials, config);

            client.BeforeRequestEvent += RequestEventHandler;
            client.AfterResponseEvent += ResponseEventHandler;
            return(client);
        }
Пример #12
0
        public void OrganizationsCreateOrganization()
        {
            #region to-create-a-new-organization-with-consolidated-billing-features-only

            var client   = new AmazonOrganizationsClient();
            var response = client.CreateOrganization(new CreateOrganizationRequest
            {
                FeatureSet = "CONSOLIDATED_BILLING"
            });

            Organization organization = response.Organization;

            #endregion
        }
Пример #13
0
        public void OrganizationsCancelHandshake()
        {
            #region to-cancel-a-handshake-sent-to-a-member-account-1472501320506

            var client   = new AmazonOrganizationsClient();
            var response = client.CancelHandshake(new CancelHandshakeRequest
            {
                HandshakeId = "h-examplehandshakeid111"
            });

            Handshake handshake = response.Handshake;

            #endregion
        }
Пример #14
0
        public void OrganizationsAttachPolicy()
        {
            #region to-attach-a-policy-to-an-account

            var client   = new AmazonOrganizationsClient();
            var response = client.AttachPolicy(new AttachPolicyRequest
            {
                PolicyId = "p-examplepolicyid111",
                TargetId = "333333333333"
            });


            #endregion
        }
Пример #15
0
        public void OrganizationsAcceptHandshake()
        {
            #region to-accept-a-handshake-from-another-account-1472500561150

            var client   = new AmazonOrganizationsClient();
            var response = client.AcceptHandshake(new AcceptHandshakeRequest
            {
                HandshakeId = "h-examplehandshakeid111"
            });

            Handshake handshake = response.Handshake;

            #endregion
        }
Пример #16
0
        public void OrganizationsCreateAccount()
        {
            #region to-create-a-new-account-that-is-automatically-part-of-the-organization-1472501463507

            var client   = new AmazonOrganizationsClient();
            var response = client.CreateAccount(new CreateAccountRequest
            {
                AccountName = "Production Account",
                Email       = "*****@*****.**"
            });

            CreateAccountStatus createAccountStatus = response.CreateAccountStatus;

            #endregion
        }
Пример #17
0
        public void OrganizationsCreateOrganizationalUnit()
        {
            #region to-create-a-new-organizational-unit

            var client   = new AmazonOrganizationsClient();
            var response = client.CreateOrganizationalUnit(new CreateOrganizationalUnitRequest
            {
                Name     = "AccountingOU",
                ParentId = "r-examplerootid111"
            });

            OrganizationalUnit organizationalUnit = response.OrganizationalUnit;

            #endregion
        }
Пример #18
0
        /// <summary>
        /// Initializes the Organizations client and then calls
        /// DeleteOrganizationAsync to delete the organization.
        /// </summary>
        public static async Task Main()
        {
            // Create the client object using the default account.
            IAmazonOrganizations client = new AmazonOrganizationsClient();

            var response = await client.DeleteOrganizationAsync(new DeleteOrganizationRequest());

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine("Successfully deleted Organization.");
            }
            else
            {
                Console.WriteLine("Could not delete Organization.");
            }
        }
Пример #19
0
        /// <summary>
        /// Initializes an Orginizations client object and uses it to create
        /// the new Account with the name specified in accountName.
        /// </summary>
        static async Task Main()
        {
            IAmazonOrganizations client = new AmazonOrganizationsClient();
            var accountName             = "ExampleAccount";
            var email = "*****@*****.**";

            var request = new CreateAccountRequest
            {
                AccountName = accountName,
                Email       = email,
            };

            var response = await client.CreateAccountAsync(request);

            var status = response.CreateAccountStatus;

            Console.WriteLine($"The staus of {status.AccountName} is {status.State}.");
        }
        public JObject FunctionHandler(JObject input)
        {
            LambdaLogger.Log(input.ToString());
            string requestId = input.SelectToken("CreateAccountStatus.CreateAccountStatus.Id").ToString();

            AmazonOrganizationsClient          client  = new AmazonOrganizationsClient();
            DescribeCreateAccountStatusRequest request = new DescribeCreateAccountStatusRequest()
            {
                CreateAccountRequestId = requestId
            };

            DescribeCreateAccountStatusResponse response = client.DescribeCreateAccountStatusAsync(request).Result;

            JObject outputObject = new JObject();

            outputObject.Add("CreateAccountStatus", JObject.FromObject(response));
            outputObject.Add("EventData", input.SelectToken("EventData"));

            return(outputObject);
        }
Пример #21
0
        /// <summary>
        /// Initializes the Organizations client object and then calls the
        /// AttachPolicyAsync method to attach the policy to the root
        /// organization.
        /// </summary>
        public static async Task Main()
        {
            IAmazonOrganizations client = new AmazonOrganizationsClient();
            var policyId = "p-c0hsjgmq";
            var targetId = "r-sso8";

            var request = new AttachPolicyRequest
            {
                PolicyId = policyId,
                TargetId = targetId,
            };

            var response = await client.AttachPolicyAsync(request);

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine($"Successfully attached Policy ID {policyId} to Target ID: {targetId}.");
            }
            else
            {
                Console.WriteLine("Was not successful in attaching the policy.");
            }
        }
        /// <summary>
        /// Initializes the Organizations client object and calls
        /// DeleteOrganizationalUnitAsync to delete the Organizational Unit
        /// with the selected ID.
        /// </summary>
        public static async Task Main()
        {
            // Create the client object using the default account.
            IAmazonOrganizations client = new AmazonOrganizationsClient();

            var orgUnitId = "ou-sso8-r0fkibej";

            var request = new DeleteOrganizationalUnitRequest
            {
                OrganizationalUnitId = orgUnitId,
            };

            var response = await client.DeleteOrganizationalUnitAsync(request);

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine($"Successfully deleted the Organization Unit with ID: {orgUnitId}.");
            }
            else
            {
                Console.WriteLine($"Could not delete the Organization Unit with ID: {orgUnitId}.");
            }
        }
Пример #23
0
        /// <summary>
        /// Initializes an Organizations client object, and then calls its
        /// ListPolliciesAsync method.
        /// </summary>
        public static async Task Main()
        {
            // Create the client object using the default account.
            IAmazonOrganizations client = new AmazonOrganizationsClient();

            // The value for the Filter parameter is required and must must be
            // one of the following:
            //     AISERVICES_OPT_OUT_POLICY
            //     BACKUP_POLICY
            //     SERVICE_CONTROL_POLICY
            //     TAG_POLICY
            var request = new ListPoliciesRequest
            {
                Filter     = "SERVICE_CONTROL_POLICY",
                MaxResults = 5,
            };

            var response = new ListPoliciesResponse();

            try
            {
                do
                {
                    response = await client.ListPoliciesAsync(request);

                    response.Policies.ForEach(p => DisplayPolicies(p));
                    if (response.NextToken is not null)
                    {
                        request.NextToken = response.NextToken;
                    }
                } while (response.NextToken is not null);
            }
            catch (AWSOrganizationsNotInUseException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #24
0
        // public CreateAccountResponse FunctionHandler(JObject input)
        public JObject FunctionHandler(JObject input)
        {
            LambdaLogger.Log(input.ToString());
            // string tempJson = "{  \"CreateAccountStatus\": {    \"AccountId\": null,    \"AccountName\": \"TEST - Test 2\",    \"CompletedTimestamp\": \"0001-01-01T00:00:00\",    \"FailureReason\": null,    \"Id\": \"car-c7464020363411e9aa4b50d5029d06f1\",    \"RequestedTimestamp\": \"2019-02-21T23:59:52.345Z\",    \"State\": {      \"Value\": \"IN_PROGRESS\"    }  },  \"ResponseMetadata\": {    \"RequestId\": \"c7108b16-3634-11e9-bafa-ad7d8c47e1d6\",    \"Metadata\": {}  },  \"ContentLength\": 159,  \"HttpStatusCode\": 200}";
            // JObject response = JObject.FromObject(JsonConvert.DeserializeObject(tempJson));

            AmazonOrganizationsClient client = new AmazonOrganizationsClient();

            CreateAccountRequest request = new CreateAccountRequest()
            {
                AccountName = input.SelectToken("accountName").ToString(),
                Email       = input.SelectToken("emailAddress").ToString(),
                RoleName    = "AWSAccountAdmin"
            };

            CreateAccountResponse response = client.CreateAccountAsync(request).Result;

            JObject outputObject = new JObject();

            outputObject.Add("CreateAccountStatus", JObject.FromObject(response));
            outputObject.Add("EventData", input);

            return(outputObject);
        }