2

I have setup a process for installing and setting up my application stack on a ubuntu base image and then creating an AMI from the machine. All of this is automated using packer. Now once I have the ami-id once packer is done I manually create a new launch configuration and update my ASG configuration and then schedule scale up and scale down action which gets rid of the old instances.

So what I am looking for is:

  1. Please suggest a better way to update my application stack whenever there is a new update for any software version (e.g ngnix ruby etc)
  2. How can I automate the roll out process so the new ami is picked up and old instance should degrade.
Umer
  • 250
  • 4
  • 14
  • Have you looked at AWS Systems Manager? – Rajesh Dec 12 '17 at 09:58
  • No, I haven't. Will it be able to solve both my issues? I have read about using Cloudformation to update my stack that can take of the roll out process. Can you point me towards an example using AWS system manager? – Umer Dec 12 '17 at 10:25
  • Apologies.. I was assuming that you create a base image for updating patches. In case you wish to deploy your application updates you can use AWS CodeDeploy. This way you do not need to create AMI when you want to update your application (https://aws.amazon.com/codedeploy/) – Rajesh Dec 12 '17 at 11:25

1 Answers1

3

There is a good strategy for this in Faster Auto Scaling in AWS CloudFormation Stacks with Lambda-backed Custom Resources

To orchestrate this process, you bootstrap a reference instance with a user data script, use wait conditions to trigger an AMI capture, and finally create an Auto Scaling group launch configuration that references the newly created AMI. The reference instance that is used to capture the AMI can then be terminated, or it can be repurposed for administrative access or for performing scheduled tasks.

The process does not use Packer and does not require a dedicated server for creating the AMI, and instead uses a Lambda-backed custom resource.

Second Option

As you already have your AMI creation in Packer working, you should consider using Lambda to copy your existing Launch Configuration with the updated AMI. You can see a good approach to this from Patch an AMI and Update an Auto Scaling Group:

The following example builds on the Simplify AMI Patching Using Automation, Lambda, and Parameter Store example by adding a step that updates an Auto Scaling group with the newly-patched AMI. This approach ensures that new images are automatically made available to different computing environments that use Auto Scaling groups.

The final step of the Automation workflow in this example uses an AWS Lambda function to copy an existing launch configuration and set the AMI ID to the newly-patched AMI. The Auto Scaling group is then updated with the new launch configuration. In this type of Auto Scaling scenario, users could terminate existing instances in the Auto Scaling group to force a new instance to launch that uses the new image. Or, users could wait and allow scale-in or scale-out events to naturally launch newer instances.

Rodrigo Murillo
  • 13,080
  • 2
  • 29
  • 50