Skip to content

Instantly share code, notes, and snippets.

@goneri
Created June 11, 2020 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goneri/7a7a8235a94aa4d6774e0be2268d144f to your computer and use it in GitHub Desktop.
Save goneri/7a7a8235a94aa4d6774e0be2268d144f to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eux
aws --version |grep aws-cli || pip install awscli
bucket_name="nodepool-images-test"
if ! aws s3 ls s3://${bucket_name}; then
aws s3 mb s3://${bucket_name} --region us-east-2
fi
for image_local_path in $(find /opt/nodepool/images -maxdepth 1 -name 'centos-8-0000002059.raw'); do
file_name=$(basename ${image_local_path})
if ! aws s3 ls s3://${bucket_name}/${file_name}; then
aws s3 cp ${image_local_path} s3://${bucket_name}
fi
echo '[{"Description":"nodepool-import","Format":"raw","UserBucket":{"S3Bucket":"nodepool-images-test","S3Key":"centos-8-0000002059.raw"}}]' > /tmp/containers.json
aws ec2 import-image --description "nodepool_image_centos-8-0000002059.raw" --disk-containers file:///tmp/containers.json --region us-east-2
echo You can now follow the deploy with: aws ec2 describe-import-image-tasks --import-task-ids XXXX --region us-east-2
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment