Пример #1
0
        async static Task <List <SendDataPoint> > GetSesStatsForAccount(string Account)
        {
            string strRoleARN = "arn:aws:iam::" + Account + ":role/" + AssumedRoleName;

            Amazon.SecurityToken.AmazonSecurityTokenServiceClient stsClient = new Amazon.SecurityToken.AmazonSecurityTokenServiceClient();
            var assumeRoleResponse = await stsClient.AssumeRoleAsync(new Amazon.SecurityToken.Model.AssumeRoleRequest {
                RoleArn = strRoleARN, RoleSessionName = "TempSession"
            });


            SessionAWSCredentials sessionCredentials =
                new SessionAWSCredentials(assumeRoleResponse.Credentials.AccessKeyId,
                                          assumeRoleResponse.Credentials.SecretAccessKey,
                                          assumeRoleResponse.Credentials.SessionToken);

            var regions = new Amazon.RegionEndpoint[] { Amazon.RegionEndpoint.USEast1, Amazon.RegionEndpoint.USWest2, Amazon.RegionEndpoint.EUWest1 };

            List <SendDataPoint> lst = new List <SendDataPoint>();

            foreach (var region in regions)
            {
                Console.WriteLine($"Checking {region.ToString()} for account {Account}");

                AmazonSimpleEmailServiceClient sesClient = new AmazonSimpleEmailServiceClient(sessionCredentials, region);

                var response = await sesClient.GetSendStatisticsAsync();

                lst.AddRange(response.SendDataPoints);
            }

            return(lst);
        }