Description:
We are encountering an issue with our ECS Fargate task where it fails to access the IAM credentials from the EC2 Instance Metadata Service. The error message observed in the application logs is:
Error: Unable to get IAM security credentials from EC2 Instance Metadata Service.
We have confirmed that the Fargate metadata endpoint http://169.254.170.2/v2/metadata is reachable from within the ECS task, as indicated by the debug logs.
Background Information:
- ECS Cluster Type: ECS Fargate.
- IAM Role for ECS Task: The ECS task is associated with the IAM role.
- IAM Role Permissions: The role has the necessary permissions, including:

Task Definition: The AWS_REGION environment variable is set correctly in the ECS task definition.
Observations:
- The task has been configured with assignPublicIp: ENABLED, and it is able to reach other network resources without any issues.
- The metadata endpoint at http://169.254.170.2/v2/metadata returns expected information when queried, confirming network access to the endpoint.
- The IAM role used for the ECS task has the necessary permissions, yet the application encounters an issue when trying to use the role to access AWS resources such as S3.
- Logs:
Here is a sample of the error observed in the logs:
[Error] Failed to get Caller Identity. Error: Unable to get IAM security credentials from EC2 Instance Metadata Service.
Despite having access to the Fargate metadata endpoint, the application still fails when trying to assume the role or retrieve credentials.
Request for Assistance:
We suspect the issue might be related to how the IAM credentials are being provided to the ECS task, but we are unable to pinpoint the exact cause. Could you help us verify the configuration and identify any potential misconfiguration that might be preventing the ECS task from obtaining and using IAM credentials correctly?
Please let us know if there are any additional checks or configurations we should perform to resolve this issue.
Thanks for your input! Just to clarify, I’m authenticating and pushing artifacts to S3 using the IAM role attached to my ECS Fargate task. For authentication, I’m not using EC2 instance metadata; instead, I’m leveraging the credentials that Fargate provides to the container.
Here’s a snippet of the code for your reference:
For context, here’s the code snippet we are using with the IAmazonS3 client to interact with the S3 bucket: `var s3Client = new AmazonS3Client();
// This is used to get the caller identity (for troubleshooting or verification purposes) var stsClient = new AmazonSecurityTokenServiceClient(); var identityResponse = stsClient.GetCallerIdentity(new GetCallerIdentityRequest()); LogManager.GetLogger(Categories.General).Info($"Caller Identity: {identityResponse.Arn}");`