Guest User

Untitled

a guest
Jan 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. # 1. Find the latest ID of the AMI:
  2. NEW_AMI_ID=$(aws ec2 describe-images \
  3. --filters Name=name,Values=*WHATEVER AMI NAME YOU ARE LOOKING FOR* \
  4. --query 'Images[*].[ImageId,CreationDate]' \
  5. --output text | sort -k2 -r | head -n1 | awk {'print $1'})
  6.  
  7. # 2. Modify a PARAMETERS.vars.json that is being used by AWS CLI in step 3.:
  8. tmp=$(mktemp)
  9. jq -r '[ .[] | select(.ParameterKey=="AmiId").ParameterValue |= '\"$NEW_AMI_ID\"' ]' \
  10. PARAMETERS.vars.json > "$tmp" && mv "$tmp" PARAMETERS.vars.json
  11.  
  12. # 3. Create a stack using the above file with the latest AMI ID:
  13. AWS_PROFILE=test aws cloudformation create-stack \
  14. --stack-name WHATEVER \
  15. --template-body file://WHATEVER.template.yaml \
  16. --tags Key=BLA,Value=BLA \
  17. --parameters file://PARAMETERS.vars.json \
  18. --capabilities CAPABILITY_NAMED_IAM \
  19. --profile ${AWS_PROFILE}
Add Comment
Please, Sign In to add comment