Here the same issue. Containers has eventual errors log errors like this:
error parsing user Error [CredentialsError]: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
Is related to missing get EC2 metadata and containers crash due missing credentials. The error is reproduced when instance metadata IMDSv2 is changed from "optional" to "required" and container is recreated. This change was done without consider any additional settings change:
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html#Considerations
If you have awsvpc networking mode you can bypass with the default value HttpPutResponseHopLimit = "1"
"MetadataOptions": {
"State": "applied",
"HttpTokens": "optional",
"HttpPutResponseHopLimit": "1",
"HttpEndpoint": "enabled"
},
But if you bridge networking mode , then you need set minimum of "2" hops in order the containers could to reach out metadata.
"MetadataOptions": {
"State": "applied",
"HttpTokens": "optional",
"HttpPutResponseHopLimit": "2",
"HttpEndpoint": "enabled"
},
You can use modify-instance-metadata-options in awscli:
aws ec2 modify-instance-metadata-options \
--instance-id <instance_id> \
--http-put-response-hop-limit 2 \
--http-endpoint enabled
Or from Terraform, from resource "aws_launch_template"
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template
with followwing metadata options:
metadata_options {
http_endpoint = "enabled"
http_tokens = "required"
http_put_response_hop_limit = 2
instance_metadata_tags = "enabled"
}
Now from your EC2 or inside the containers, Token should be receive a response:
TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2ata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/
/app_start # TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2ata-token: $TOKEN" -
v http://169.254.169.254/latest/meta-data/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 56 100 56 0 0 6784 0 --:--:-- --:--:-- --:--:-- 8000
* processing: http://169.254.169.254/latest/meta-data/
* Trying 169.254.169.254:80...
* Connected to 169.254.169.254 (169.254.169.254) port 80
> GET /latest/meta-data/ HTTP/1.1
> Host: 169.254.169.254
> User-Agent: curl/8.2.1
> Accept: */*
> X-aws-ec2ata-token: xxxxxxx
>
< HTTP/1.1 401 Unauthorized
< Content-Length: 0
< Date: Thu, 14 Sep 2023 11:51:42 GMT
< Server: EC2ws
< Connection: close
< Content-Type: text/plain
<
* Closing connection
http-put-response-hop-limit
a bad practice, or it doesn't really matter ? – Vitus