3

I woud like to create an AMI (Amazon Machine Image) from a running EC2 instance using Packers..

Here is my usecase:
1) Use packer to generate the base AMI and start the EC2 instance
2) Have user data configuration on the EC2 instance.. (Human Intervention needed here)
3) Generate an app specific AMI from step#2 using Packer

I don't want to use the "provisioner" provided by packers. I need a human intervention at step#2

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
user3006942
  • 155
  • 2
  • 12

2 Answers2

2

The point of Packer seems to be to eliminate human intervention from the build process in order to make deployment consistent. However, per-instance data can be passed in through Packer user variables, which can be passed on the command line:

$ packer build \
    -var 'aws_access_key=foo' \
    -var 'aws_secret_key=bar' \
    template.json

or via a config file:

$ packer build -var-file=variables.json template.json
Jeffrey Hantin
  • 35,734
  • 7
  • 75
  • 94
  • I am looking at something in Packer that can take an instance ID and generate the AMI from that instance.. – user3006942 Nov 19 '13 at 02:17
  • 1
    Creating an image from a running instance is a single AWS command, [ec2-create-image](http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-CreateImage.html). From there, one of the standard builders should work. – Jeffrey Hantin Nov 19 '13 at 02:26
  • Better use a new [CLI](http://docs.aws.amazon.com/cli/latest/reference/ec2/create-image.html) – Evgeny Goldin Nov 19 '13 at 02:30
  • Use commands to achieve this, remember this will reboot the instance while creating an ami.So make sure things are in shape once ami is created. when launching ami's, instance status should be checked as running before exposing it. – Bijendra Nov 19 '13 at 08:10
0

I would agree with the ec2-create-image approach. Once your packer build completes- you would need a second packer build to accomplish this. You could have a webhook kick this off, say, with Atlas.

Have you considered doing the modifications locally (in VMWare) and then installing ec2 tools, and using ec2-convert? something like the following?

aws ec2 import-image --cli-input-json '{ "Platform": "Linux", 
"Architecture": "x86_64", "Description": "Some Centos AMI v21.2.1", 
"DiskContainers": [{ "Description": "Some_App", "UserBucket": { 
"S3Bucket": "centos-builds", "S3Key": "some-build-ami.ova"}}]}'

This will end with an AMI.

JP Bourget
  • 56
  • 1
  • 7