github.com/kaixiang/packer@v0.5.2-0.20140114230416-1f5786b0d7f1/website/source/docs/builders/amazon-ebs.html.markdown (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Amazon AMI Builder (EBS backed)"
     4  ---
     5  
     6  # AMI Builder (EBS backed)
     7  
     8  Type: `amazon-ebs`
     9  
    10  The `amazon-ebs` builder is able to create Amazon AMIs backed by EBS
    11  volumes for use in [EC2](http://aws.amazon.com/ec2/). For more information
    12  on the difference betwen EBS-backed instances and instance-store backed
    13  instances, see the
    14  ["storage for the root device" section in the EC2 documentation](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ComponentsAMIs.html#storage-for-the-root-device).
    15  
    16  This builder builds an AMI by launching an EC2 instance from a source AMI,
    17  provisioning that running machine, and then creating an AMI from that machine.
    18  This is all done in your own AWS account. The builder will create temporary
    19  keypairs, security group rules, etc. that provide it temporary access to
    20  the instance while the image is being created. This simplifies configuration
    21  quite a bit.
    22  
    23  The builder does _not_ manage AMIs. Once it creates an AMI and stores it
    24  in your account, it is up to you to use, delete, etc. the AMI.
    25  
    26  ## Configuration Reference
    27  
    28  There are many configuration options available for the builder. They are
    29  segmented below into two categories: required and optional parameters. Within
    30  each category, the available configuration keys are alphabetized.
    31  
    32  Required:
    33  
    34  * `access_key` (string) - The access key used to communicate with AWS.
    35    If not specified, Packer will attempt to read this from environmental
    36    variables `AWS_ACCESS_KEY_ID` or `AWS_ACCESS_KEY` (in that order).
    37  
    38  * `ami_name` (string) - The name of the resulting AMI that will appear
    39    when managing AMIs in the AWS console or via APIs. This must be unique.
    40    To help make this unique, use a function like `timestamp` (see
    41    [configuration templates](/docs/templates/configuration-templates.html) for more info)
    42  
    43  * `instance_type` (string) - The EC2 instance type to use while building
    44    the AMI, such as "m1.small".
    45  
    46  * `region` (string) - The name of the region, such as "us-east-1", in which
    47    to launch the EC2 instance to create the AMI.
    48  
    49  * `secret_key` (string) - The secret key used to communicate with AWS.
    50    If not specified, Packer will attempt to read this from environmental
    51    variables `AWS_SECRET_ACCESS_KEY` or `AWS_SECRET_KEY` (in that order).
    52  
    53  * `source_ami` (string) - The initial AMI used as a base for the newly
    54    created machine.
    55  
    56  * `ssh_username` (string) - The username to use in order to communicate
    57    over SSH to the running machine.
    58  
    59  Optional:
    60  
    61  * `ami_block_device_mappings` (array of block device mappings) - Add the block
    62    device mappings to the AMI. The block device mappings allow for keys:
    63    "device\_name" (string), "virtual\_name" (string), "snapshot\_id" (string),
    64    "volume\_type" (string), "volume\_size" (int), "delete\_on\_termination"
    65    (bool), "no\_device" (bool), and "iops" (int).
    66  
    67  * `ami_description` (string) - The description to set for the resulting
    68    AMI(s). By default this description is empty.
    69  
    70  * `ami_groups` (array of string) - A list of groups that have access
    71    to launch the resulting AMI(s). By default no groups have permission
    72    to launch the AMI.
    73  
    74  * `ami_product_codes` (array of string) - A list of product codes to
    75    associate with the AMI. By default no product codes are associated with
    76    the AMI.
    77  
    78  * `ami_regions` (array of string) - A list of regions to copy the AMI to.
    79    Tags and attributes are copied along with the AMI. AMI copying takes time
    80    depending on the size of the AMI, but will generally take many minutes.
    81  
    82  * `ami_users` (array of string) - A list of account IDs that have access
    83    to launch the resulting AMI(s). By default no additional users other than the user
    84    creating the AMI has permissions to launch it.
    85  
    86  * `iam_instance_profile` (string) - The name of an
    87    [IAM instance profile](http://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html)
    88    to launch the EC2 instance with.
    89  
    90  * `launch_block_device_mappings` (array of block device mappings) - Add the
    91    block device mappings to the launch instance. The block device mappings are
    92    the same as `ami_block_device_mappings` above.
    93  
    94  * `run_tags` (object of key/value strings) - Tags to apply to the instance
    95    that is _launched_ to create the AMI. These tags are _not_ applied to
    96    the resulting AMI unless they're duplicated in `tags`.
    97  
    98  * `security_group_id` (string) - The ID (_not_ the name) of the security
    99    group to assign to the instance. By default this is not set and Packer
   100    will automatically create a new temporary security group to allow SSH
   101    access. Note that if this is specified, you must be sure the security
   102    group allows access to the `ssh_port` given below.
   103  
   104  * `security_group_ids` (array of string) - A list of security groups as
   105    described above. Note that if this is specified, you must omit the
   106    security_group_id.
   107  
   108  * `ssh_port` (int) - The port that SSH will be available on. This defaults
   109    to port 22.
   110  
   111  * `ssh_timeout` (string) - The time to wait for SSH to become available
   112    before timing out. The format of this value is a duration such as "5s"
   113    or "5m". The default SSH timeout is "1m", or one minute.
   114  
   115  * `subnet_id` (string) - If using VPC, the ID of the subnet, such as
   116    "subnet-12345def", where Packer will launch the EC2 instance.
   117  
   118  * `associate_public_ip_address` (bool) - If using a non-default VPC, public
   119    IP addresses are not provided by default. If this is toggled, your new
   120  	instance will get a Public IP.
   121  
   122  * `tags` (object of key/value strings) - Tags applied to the AMI.
   123  
   124  * `user_data` (string) - User data to apply when launching the instance.
   125    Note that you need to be careful about escaping characters due to the
   126    templates being JSON. It is often more convenient to use `user_data_file`,
   127    instead.
   128  
   129  * `user_data_file` (string) - Path to a file that will be used for the
   130    user data when launching the instance.
   131  
   132  * `vpc_id` (string) - If launching into a VPC subnet, Packer needs the
   133    VPC ID in order to create a temporary security group within the VPC.
   134  
   135  * `avail_zone` (string) - Destination availability zone to launch instance in.
   136    Leave this empty to allow Amazon to auto-assign.
   137  
   138  ## Basic Example
   139  
   140  Here is a basic example. It is completely valid except for the access keys:
   141  
   142  <pre class="prettyprint">
   143  {
   144    "type": "amazon-ebs",
   145    "access_key": "YOUR KEY HERE",
   146    "secret_key": "YOUR SECRET KEY HERE",
   147    "region": "us-east-1",
   148    "source_ami": "ami-de0d9eb7",
   149    "instance_type": "t1.micro",
   150    "ssh_username": "ubuntu",
   151    "ami_name": "packer-quick-start {{timestamp}}",
   152  }
   153  </pre>
   154  
   155  <div class="alert alert-block alert-info">
   156  <strong>Note:</strong> Packer can also read the access key and secret
   157  access key from environmental variables. See the configuration reference in
   158  the section above for more information on what environmental variables Packer
   159  will look for.
   160  </div>
   161  
   162  ## Accessing the Instance to Debug
   163  
   164  If you need to access the instance to debug for some reason, run the builder
   165  with the `-debug` flag. In debug mode, the Amazon builder will save the
   166  private key in the current directory and will output the DNS or IP information
   167  as well. You can use this information to access the instance as it is
   168  running.
   169  
   170  ## AMI Block Device Mappings Example
   171  
   172  Here is an example using the optional AMI block device mappings. This will add
   173  the /dev/sdb and /dev/sdc block device mappings to the finished AMI.
   174  
   175  <pre class="prettyprint">
   176  {
   177    "type": "amazon-ebs",
   178    "access_key": "YOUR KEY HERE",
   179    "secret_key": "YOUR SECRET KEY HERE",
   180    "region": "us-east-1",
   181    "source_ami": "ami-de0d9eb7",
   182    "instance_type": "t1.micro",
   183    "ssh_username": "ubuntu",
   184    "ami_name": "packer-quick-start {{timestamp}}",
   185    "ami_block_device_mappings": [
   186        {
   187            "device_name": "/dev/sdb",
   188            "virtual_name": "ephemeral0"
   189        },
   190        {
   191            "device_name": "/dev/sdc",
   192            "virtual_name": "ephemeral1"
   193        }
   194    ]
   195  }
   196  </pre>
   197  
   198  ## Tag Example
   199  
   200  Here is an example using the optional AMI tags. This will add the tags
   201  "OS_Version" and "Release" to the finished AMI.
   202  
   203  <pre class="prettyprint">
   204  {
   205    "type": "amazon-ebs",
   206    "access_key": "YOUR KEY HERE",
   207    "secret_key": "YOUR SECRET KEY HERE",
   208    "region": "us-east-1",
   209    "source_ami": "ami-de0d9eb7",
   210    "instance_type": "t1.micro",
   211    "ssh_username": "ubuntu",
   212    "ami_name": "packer-quick-start {{timestamp}}",
   213    "tags": {
   214      "OS_Version": "Ubuntu",
   215      "Release": "Latest"
   216    }
   217  }
   218  </pre>