while trying to retrieve the temporary credentials from Amazon using AWS SDK , i am facing this issue.

0

hi , i have tried using this 2 types of approaches to retrieve temporary credentials from AWS account , getting the same error as shown in the screenshot . Please let me knw if there are any better approaches or if any fix for the error , Thank you. // 1st apporach

AssumeRoleRequest request = new AssumeRoleRequest();
                request.RoleArn = "arn:aws:iam::532634566192:role/ap-redshift";
                request.RoleSessionName = "newsessionanme";
                client = new AmazonSecurityTokenServiceClient();
                AssumeRoleResponse resp = client.AssumeRole(request);
                Console.WriteLine(resp.Credentials);
                Console.ReadLine();

// 2nd approach

client = new AmazonSecurityTokenServiceClient();
            var response = client.AssumeRole(new AssumeRoleRequest
            {
                RoleArn = "arn:aws:iam::532634566192:role/ap-redshift",
                RoleSessionName = "newsessionanme"
            });
            AssumedRoleUser assumedRoleUser = response.AssumedRoleUser;
            Credentials credentials = response.Credentials;

This is the error i am getting "Unable to get IAM security credentials from EC2 Instance Metadata Service.'" as also shown in the picture .

Enter image description here

질문됨 2년 전732회 조회
1개 답변
0

Hello rePost-User-9225202, thank you for reaching out!

    It appears you are encountering an issue related to IAM security credentials on SDK. The error suggest the problem that the IAM trust policy might not be correctly configured.
     
    Make sure your IAM trust policy allow allows the EC2 instance to assume the role. Check the example below.
     
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Principal": { "Service": "ec2.amazonaws.com"},
          "Action": "sts:AssumeRole"
        }
      ]
    } 
    
    If you are performing these call within a EC2 instance check this link https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#instance-metadata-security-credentials.
 
Somebody also ask a similar question over Github(https://github.com/aws/aws-sdk-net/issues/1699). Check the link to see if you can resolve your issue over there.
 
    Hope this helps.
     
    Reference:
    https://blog.gruntwork.io/authenticating-to-aws-with-instance-metadata-b6d812a86b40
답변함 8달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠