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

Heroku

Deliver your unique apps, your own way.

Heroku tackles the toil — patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (0)

ACI image

ACI.dev: Best Open-Source Composio Alternative (AI Agent Tooling)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Star our GitHub!

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️