Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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