Beispiel #1
0
        private static void LocalProfileTest()
        {
            var chain          = new CredentialProfileStoreChain();
            var awsCredentials = default(AWSCredentials);

            if (chain.TryGetAWSCredentials("default", out awsCredentials))
            {
                var aws = awsCredentials.GetCredentials();

                var request = new AwsApiGatewayRequest()
                {
                    RegionName    = "ap-southeast-2",
                    Host          = apiEndpoint,
                    AccessKey     = aws.AccessKey,
                    SecretKey     = aws.SecretKey,
                    AbsolutePath  = apiEndpointStaging,
                    JsonData      = "245",
                    RequestMethod = HttpMethod.Post
                };
                var apiRequest = new ApiRequest(request);
                var response   = apiRequest.GetResponse();

                Console.WriteLine(response.ContentLength);
            }
        }
Beispiel #2
0
        public async Task <string> Ec2IamGetTest()
        {
            var response = string.Empty;

            var iamCredentials = GetEc2Credential();

            var request = new AwsApiGatewayRequest()
            {
                RegionName    = _config.AwsRegion,
                Host          = _config.ApiEndpoint,
                AccessKey     = iamCredentials.AccessKeyId,
                SecretKey     = iamCredentials.SecretAccessKey,
                RequestMethod = HttpMethod.Get,
                AbsolutePath  = $"{_config.ApiEndpointStages}{_config.GetId}"
            };

            if (!string.IsNullOrEmpty(_config.IamAdditionalHeaders))
            {
                request.AdditionalHeaders = _config.IamAdditionalHeaders;
            }

            var apiRequest = new ApiRequest(request);

            response = await apiRequest.GetResponseStringAsync();

            return(response);
        }
Beispiel #3
0
        private static void Ec2IamTest()
        {
            var iamRoleName    = EC2InstanceMetadata.GetData("/iam/security-credentials");
            var iamRole        = EC2InstanceMetadata.GetData($"/iam/security-credentials/{iamRoleName}");
            var iamCredentials = JsonConvert.DeserializeObject <IamRoleCredentials>(iamRole);

            Console.WriteLine(iamCredentials.AccessKeyId);
            Console.WriteLine(iamCredentials.Token);

            var request = new AwsApiGatewayRequest()
            {
                RegionName    = "ap-southeast-2",
                Host          = apiEndpoint,
                AccessKey     = iamCredentials.AccessKeyId,
                SecretKey     = iamCredentials.SecretAccessKey,
                AbsolutePath  = apiEndpointStaging,
                JsonData      = "245",
                SessionToken  = iamCredentials.Token,
                RequestMethod = HttpMethod.Post
            };
            var apiRequest = new ApiRequest(request);
            var response   = apiRequest.GetResponse();

            Console.WriteLine(response.ContentLength);
        }
Beispiel #4
0
        public async Task <string> LocalProfileGetTest()
        {
            var response = string.Empty;

            var awsCredentials = GetAwsCredential();

            if (awsCredentials != null)
            {
                var aws = awsCredentials.GetCredentials();

                var request = new AwsApiGatewayRequest()
                {
                    RegionName    = _config.AwsRegion,
                    Host          = _config.ApiEndpoint,
                    AccessKey     = aws.AccessKey,
                    SecretKey     = aws.SecretKey,
                    RequestMethod = HttpMethod.Get,
                    AbsolutePath  = $"{_config.ApiEndpointStages}{_config.GetId}"
                };
                var apiRequest = new ApiRequest(request);
                response = await apiRequest.GetResponseStringAsync();
            }

            return(response);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start");

            var request = new AwsApiGatewayRequest()
            {
                RegionName    = "ap-southeast-2",
                Host          = "ApiGateway-url",
                AccessKey     = "Your-AccessKey",
                SecretKey     = "Your-SecretKey",
                AbsolutePath  = "Segments",
                JsonData      = "data",
                RequestMethod = "POST"
            };
            var apiRequest = new ApiRequest(request);
            var response   = apiRequest.GetPostResponse();

            Console.WriteLine("End");
            Console.ReadLine();
        }