0
votes

Now, i'm creating AWS AMI manually from an EC2 instance. and i would like to automate the process using Jenkins build process.

I've configured the jenkins-cloudformation plugin with the credentials and tried to trigger the cloud formation template to launch the EC2 instance. From here how can i proceed the automation process to create the AMI with in the cloud formation template?

Can someone help me on this?

1
Can you clarify what you want the end result to be like?Naguib Ihab
The tool you are looking for to automate AMI creation is packer, not cloudformation.jordanm
Verify whether you really need an ami created. You can do customizations on your instance via bootstrap actions during the boot. No need to maintain a separate AMI if all you are doing is installing some packages. Or if you do want to stick to AMI, you can do so via packer packer.ioabiydv

1 Answers

0
votes

This is an old question but here is some info for anyone trying to do such automation. You might use HashiCorp Packer for creating the image but, if you know your way around lambdas and AWS API, you do not need packer.

You can create a new AMI by launching an instance from a source AMI, customizing it the way you want, and then call AWS api to make an AMI out of the instance. Here are steps you might follow for this:

  • first, you need to find a source image. You can specify aws ec2 describe_images filters to do this.
  • once you have the image, you need launch an instance from it. Here is boto3 api to make the call.
  • while launching the instance, you will want to pass 'UserData' to it. You user data may be a few simple lines of installing packages or do advanced stuff. You can put it all into a script, host it in s3, and make UserData download and execute your script.
  • Once you are done with your work on the instance, it is time to capture it as a new AMI.

So, how would you do these and where is the glue? You can use AWS lambda to manage these steps. One lambda can find the source AMI and launch and instance from it. Another lambda can capture the image.

Once your instance is customized, you would trigger the lambda that will capture it as an AMI. You might do that by directly invoking lambda. Depending on re-usability requirements you have, you might want to trigger that lambda from SNS or CloudWatch, in that case you would send an SNS message to your SNS topic or enable/trigger your CloudWatch rule.

You cloudformation would install these lambdas and any other components that would trigger them (SNS and CloudWatch).