DEV Community

ChungWei Wei
ChungWei Wei

Posted on • Originally published at kmp.tw on

[AWS] How To Get Parameter Store From EC2 UserData

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>
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

After Boot Finished

Debug From Cloud-Init Log



cat /var/log/cloud-init.log
Enter fullscreen mode Exit fullscreen mode

Top comments (0)