How to run aws ssm get marameter in instance user data?

0

Hello I am trying to automate instance autoupdate on it start. I am using for this userdata in launch template. One of them is update .env file which we are storing in AWS Parameter Store. So, user data looks like:

#!/bin/bash -x
aws ssm get-parameters --names /dev/microservices --with-decryption --output text > /home/ubuntu/microservices/.env && pm2 reload all --update-env --time

This commnd works fine when to run it locally on the server, but if to run it in userdata then .env file is just empty. How is that possible? I have instance profile attached to EC2 launch template, to be able to read the values from AWS Parameter Store. Should i also export AWS credentials in userdata?

aws configure set aws_access_key_id "AKIAI***************" --profile user2 && aws configure set aws_secret_access_key "*************************************" --profile user2 && aws configure set region "us-east-1" --profile user2 && aws configure set output "text" --profile user2
1개 답변
0

No, access/secret keys are not needed. When you use instance profile, instance will assume a role that you set up for instance profile. Check if this role has SSM permissions.

profile picture
답변함 6달 전
  • Hello. Issue was in "--region" option missing in the aws ssm get-parameters command. Cat cloud-init-output.log helped to resolve an issue. Now i can export data from the parameter store record to the .env file. Thanks.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠