Using the below sample config. the temporary_iam_instance_profile_policy_document may not be immediately visible after a EC2 instance starts due to eventual consistency of PutRolePolicy and AddRoleToInstanceProfile. As a result, the amazon-ssm-agent service may fail to connect to SSM because the required SSM role does not available yet. This issue requires logging into the instance to manually restart the service or wait for 30 mins to self heal. (please see the packer log and ec2 amazon-ssm-agent log below)
This PR automatically creates a custom instance profile associated with AmazonSSMManagedInstanceCore managed policy when session_manager is used without specifying iam_instance_profile key attribute. If a user defines temporary_iam_instance_profile_policy_document, it will be added as an inline policy to the custom profile. This will solve the racing condition ensuring the amazon-ssm-agent service could consistently connect to SSM on the first start.
status code: 404, request id:
2024-08-25 16:54:21 ERROR EC2RoleProvider Failed to connect to Systems Manager with SSM role credentials. error calling RequestManagedInstanceRoleToken: AccessDeniedException: Systems Manager's instance management role is not configured for account: 1234567890
status code: 400, request id: 906a00a0-9eec-42b7-b385-xxxxxxxxx
2024-08-25 16:54:21 ERROR [CredentialRefresher] Retrieve credentials produced error: no valid credentials could be retrieved for ec2 identity. Default Host Management Err: error calling RequestManagedInstanceRoleToken: AccessDeniedException: Systems Manager's instance management role is not configured for account: 1234567890
status code: 400, request id: 906a00a0-9eec-42b7-b385-xxxxxxxxx
2024-08-25 16:54:21 INFO [CredentialRefresher] Sleeping for 27m6s before retrying retrieve credentials
Using the below sample config. the
temporary_iam_instance_profile_policy_document
may not be immediately visible after a EC2 instance starts due to eventual consistency ofPutRolePolicy
andAddRoleToInstanceProfile
. As a result, theamazon-ssm-agent
service may fail to connect to SSM because the required SSM role does not available yet. This issue requires logging into the instance to manually restart the service or wait for 30 mins to self heal. (please see the packer log and ec2 amazon-ssm-agent log below)This PR automatically creates a custom instance profile associated with
AmazonSSMManagedInstanceCore
managed policy whensession_manager
is used without specifyingiam_instance_profile
key attribute. If a user definestemporary_iam_instance_profile_policy_document
, it will be added as an inline policy to the custom profile. This will solve the racing condition ensuring theamazon-ssm-agent
service could consistently connect to SSM on the first start.As a bonus, this PR also supports AWS China region, closing https://github.com/hashicorp/packer-plugin-amazon/issues/50
sample config
packer build log:
The ec2 amazon-ssm-agent log: