익명 00:16

Is it possible to upload files along with initialization script on EC2 instance ...

Is it possible to upload files along with initialization script on EC2 instance when running it with AWS CLI?

I have nginx configuration files which I would like to deploy on my Ubuntu EC2 instance. I create instance using AWS CLI:

  aws ec2 run-instances --instance-type t2.micro \
    --count 1 \
    --image-id ami-0f8b8babb98cc66d0 \
    --key-name "$key_name" \
    --tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=$name}]" \
    --query "Instances[0].{$instance_fields_selection}" \
    --user-data 'file://ec2-setup'

This mostly works as expected: ec2-setup script creates some folders, installs some packages and does reboot. But I still have to upload my nginx config files manually through scp. --user-data option seems to be intended for uploading files, but in fact it is used for passing initialization script. Is it possible to toss normal non-executable file on instance when creating it using AWS CLI?



Top Answer/Comment:

Inside your user-data script you can specify all commands you need to prepare the OS. Then, it's inside the user-data script that you'll scp something.

However, you can't inject files inside your instance without scp or s3 commands in your user-data script.

상단 광고의 [X] 버튼을 누르면 내용이 보입니다