Loading...
Loading...
Assume AWS IAM role for CloudFormation operations and set temporary credentials as environment variables. Use when working with CloudFormation stacks or when authentication setup is needed before AWS CloudFormation operations.
npx skill4agent add daisuke897/dotfiles assume-cloudformation-roleprofile<profile-name>role_arnarn:aws:iam::<AWS_ACCOUNT_ID>:role/<RoleName>role_session_namecfn-write# Assume role and obtain credentials
aws sts assume-role \
--role-arn arn:aws:iam::<AWS_ACCOUNT_ID>:role/<RoleName> \
--role-session-name cfn-write \
--profile <profile-name> \
> /tmp/creds.json
# Set environment variables
export AWS_ACCESS_KEY_ID=$(jq -r '.Credentials.AccessKeyId' /tmp/creds.json)
export AWS_SECRET_ACCESS_KEY=$(jq -r '.Credentials.SecretAccessKey' /tmp/creds.json)
export AWS_SESSION_TOKEN=$(jq -r '.Credentials.SessionToken' /tmp/creds.json)
# Remove temporary file
rm /tmp/creds.jsonAWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_SESSION_TOKEN# Create stack
aws cloudformation create-stack --stack-name my-stack --template-body file://template.yaml
# Update stack
aws cloudformation update-stack --stack-name my-stack --template-body file://template.yaml
# Delete stack
aws cloudformation delete-stack --stack-name my-stack~/.aws/credentials~/.aws/configsts:AssumeRole