Situation
Get Parameter Store When EC2 Launch New Instance
How To
Add Parameter Store
Add Role Policy Into IAM Instance Profile
create new policy get-demo-parameter
and attach to iam instance profile
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "ssm:GetParameter",
"Resource": "arn:aws:ssm:ap-northeast-1:<your-account-id>:parameter/<parameter-store-name>
}
]
}
Launch New VM Instance And Add UserData
User Data Script
#!/bin/bash
export AWS_DEFAULT_REGION=ap-northeast-1
get_para=$(aws ssm get-parameter --name <parameter-name> --query Parameter.Value --output text)
echo $get_para > /tmp/para.txt
After Boot Finished
Debug From Cloud-Init Log
cat /var/log/cloud-init.log
Top comments (0)