DEV Community

ChungWei Wei
ChungWei Wei

Posted on • Originally published at kmp.tw on

1

[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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs