1
votes

I need to be able to copy some files from s3 bucket into ec2 instance during launch time . Is it possible to do so via user data section of the cloudformation template?

Fyi, I have the role attached to the instance to access s3 and I am able to copy files using aws cli but I need to be able to do so via user data inside cloudformation without using aws cli, if possible at all.

Edit--

Object in s3 is publicly accessible at the moment and the instance is using a custom red hat ami.

1
Why can't you just use same awscli commands (that worked for you "manually") in your user-data?Dusan Bajic
aws cli is not installed by default on the ami which I am using. I can install it anyways but I am exploring any other way to copy files without using aws cli.Naxi
You can use something like docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html but I would rather not go that way :)Dusan Bajic
Is the object in Amazon S3 publicly accessible, or is it only accessible via the assigned IAM Role? Which operating system is on the instance?John Rotenstein
@John Yes. It's publicly accessible at the moment. The instance is using a custom RedHat image.Naxi

1 Answers

1
votes

If the object in Amazon S3 is publicly accessible, you could download it with curl:

curl -o output.file https://my-bucket.s3-us-west-2.amazonaws.com/file.txt

If wget is installed, you could use that instead.

If the object is private, it will require authentication using the role. This will require some form of software to be installed, so it would be simpler to just install the AWS CLI.