Skip to content

Instantly share code, notes, and snippets.

@toabctl
Created November 22, 2022 10:57
Show Gist options
  • Save toabctl/6f4b3aed630a28b7801b136b42570102 to your computer and use it in GitHub Desktop.
Save toabctl/6f4b3aed630a28b7801b136b42570102 to your computer and use it in GitHub Desktop.
Images from SSM for different regions
#!/bin/bash -eu
# this is 2P Ubuntu Pro Xenial
SSM_ID=prod-f6ogoaqs7lwre/ubuntu-pro-16.04-lts
# get a AMI via SSM from us-east-1
US_EAST_1_AMI=$(aws --region us-east-1 ssm get-parameters --names "/aws/service/marketplace/${SSM_ID}" --query 'Parameters[0].Value' --output text)
echo $US_EAST_1_AMI
# get the AMI name via describe-images
US_EAST_1_IMAGE_NAME=$(aws --region us-east-1 ec2 describe-images --image-ids ${US_EAST_1_AMI}|jq -r '.Images[].Name')
echo $US_EAST_1_IMAGE_NAME
# get the AMI product code
US_EAST_1_IMAGE_PRODUCT_CODE=$(aws --region us-east-1 ec2 describe-images --image-ids ${US_EAST_1_AMI}|jq -r '.Images[].ProductCodes[].ProductCodeId')
echo $US_EAST_1_IMAGE_PRODUCT_CODE
# query in another region for the same AMI name and AMI product code - that results in **multiple** images
aws --region sa-east-1 ec2 describe-images --include-deprecated --filters "Name=name,Values=$US_EAST_1_IMAGE_NAME" "Name=product-code,Values=$US_EAST_1_IMAGE_PRODUCT_CODE"|jq '.Images[].Name'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment