amazon-ssm-agent service fails connecting to SSM due to eventual consistency #503
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 #50
sample config
packer build log:
The ec2 amazon-ssm-agent log: