Score:0

How to copy a file to aws ec2 instance and use it in the user-data?

cn flag

I have an rpm file for an application which is generated daily that I want to install on an EC2 server using user-data of ec2-instance using terraform.

I got file provisioner in a search result, but found that it will do the step after user-data.

Any suggestions how to do that?

Tim avatar
gp flag
Tim
sFtp the file to the instance using your ssh key, or put it on a web server and use wget to download it.
Uday Kiran Reddy avatar
cn flag
no it should be done before user-data. And creating a separate webserver for this file is not feasible
Tim avatar
gp flag
Tim
Read the first part of my comment again. Your post is a little ambiguous, if you need help please be precise.
Uday Kiran Reddy avatar
cn flag
I didn't understand what is ambiguous in this. I mentioned clearly it is user-data of aws ec2 instance. For more information on user-data follow this link https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
Uday Kiran Reddy avatar
cn flag
And, sFtp also works after user-data only.
Tim avatar
gp flag
Tim
Oh, I think I understand now. Every time an instance starts you want to install something in an RPM file. A better way to ask a question is to say what you're trying to achieve, rather than asking how to achieve the steps you think you need.
Score:0
gp flag
Tim

Option One - Make File Available

Given the information you've given in the comments I think your best or perhaps your only option is to make the RPM file available on a web server somewhere the user-data script can access it. If this is a private rpm I would put it on S3 with the bucket configured as a web server, use an S3 endpoint in the VPC, and ensure the S3 bucket only accepts requests from that endpoint.

Option Two - Create an AMI

Instead of installing the RPM in the user-data script every time the instance starts, have you considered making a golden image? That way the RPM is installed once manually, then every instance created has the RPM installed. The other advantage is the instance starts faster.

The general steps to do this are:

  • Create an instance
  • Install the RPM manually
  • Stop the instance
  • Create an image / AMI

You then use the custom AMI to start new instances.

Even if this doesn't solve your problem, it may help others with a similar problem in future.

Uday Kiran Reddy avatar
cn flag
this rpm generates on daily basis, so creating an image is not feasible right
Tim avatar
gp flag
Tim
That's unusual. I think you may need to put it onto a web server - e.g. S3 to bootstrap it. You might be able to use AWS Image Builder to build a new server image each day.
Uday Kiran Reddy avatar
cn flag
why creating a new ami is a solution to install just an rpm. And it is not unusual as that rpm is generated by us on daily basis whenever new change in our code. Please suggest if you have any other option
Tim avatar
gp flag
Tim
I've given you another option in the file. You'll find you get better answers faster if you give people all the information up front. I've edited your question a bit to add information you've provided in comments.
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.