Skip to content

Commit 32edb48

Browse files
committed
general quol refactor to propagate-image script
1 parent 8eef991 commit 32edb48

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

sync/propagate-image.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ if [[ -z $source_ami || -z $source_region ]]; then
99
fi
1010

1111
RESF_AMI_ACCOUNT_ID=792107900819
12+
export AWS_REGION=us-east-1
13+
export AWS_PROFILE=resf-ami
1214

13-
REGIONS=$(aws --profile resf-ami ec2 describe-regions \
15+
REGIONS=$(aws ec2 describe-regions \
1416
--all-regions \
1517
--query "Regions[].{Name:RegionName}" \
1618
--output text | grep -vE "$source_region")
1719

18-
SOURCE_AMI_NAME=$(aws --profile resf-ami ec2 describe-images \
20+
SOURCE_AMI_NAME=$(aws ec2 describe-images \
1921
--region "$source_region" --image-ids "$source_ami" --query 'Images[0].Name' \
2022
--output text)
2123

@@ -38,7 +40,7 @@ function copy() {
3840
continue
3941
fi
4042
echo -n "Creating copy job for $region..."
41-
ami_id=$(aws --profile resf-ami ec2 copy-image \
43+
ami_id=$(aws ec2 copy-image \
4244
--region $region \
4345
--name "${SOURCE_AMI_NAME}" \
4446
--source-image-id "${source_ami}" \
@@ -73,23 +75,23 @@ function change_privacy() {
7375
for region in "${!ami_ids[@]}"; do
7476
image_id=${ami_ids[$region]}
7577
echo -n "Making ${image_id} in $region $status..."
76-
if aws --profile resf-ami ec2 modify-image-attribute \
78+
if aws ec2 modify-image-attribute \
7779
--region $region \
7880
--image-id "$image_id" \
7981
--launch-permission "${launch_permission}" 2>/dev/null; then
8082

81-
snapshot_id=$(aws --profile resf-ami ec2 describe-images \
83+
snapshot_id=$(aws ec2 describe-images \
8284
--region $region \
8385
--image-ids "${image_id}" \
8486
--query 'Images[*].BlockDeviceMappings[0].Ebs.SnapshotId' \
8587
--output text 2>&1)
86-
permissions=$(aws --profile resf-ami ec2 describe-snapshot-attribute \
88+
permissions=$(aws ec2 describe-snapshot-attribute \
8789
--region $region \
8890
--snapshot-id "${snapshot_id}" \
8991
--attribute createVolumePermission \
9092
--query 'CreateVolumePermissions[0].Group' \
9193
--output text 2>&1)
92-
if [[ "$permissions" == "all" ]] || aws --profile resf-ami ec2 modify-snapshot-attribute \
94+
if [[ "$permissions" == "all" ]] || aws ec2 modify-snapshot-attribute \
9395
--region $region \
9496
--snapshot-id "${snapshot_id}" \
9597
--create-volume-permission "${launch_permission}" 2>/dev/null; then
@@ -124,7 +126,7 @@ function find_image_by_name() {
124126
# ami-id "name"
125127
local query="$(printf 'Images[?Name==`%s`]|[?Public==`true`].[ImageId,Name][]' "${SOURCE_AMI_NAME}")"
126128
mapfile -t res < <(
127-
aws --profile resf-ami ec2 describe-images --region $region --owners $RESF_AMI_ACCOUNT_ID \
129+
aws ec2 describe-images --region $region --owners $RESF_AMI_ACCOUNT_ID \
128130
--query "${query}" 2>/dev/null |
129131
jq -r '.|@sh'
130132
)

0 commit comments

Comments
 (0)