Score:0

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

tr flag

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?

Score:0
cn flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.