github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/website/source/docs/builders/amazon.html.md (about)

     1  ---
     2  description: |
     3      Packer is able to create Amazon AMIs. To achieve this, Packer comes with
     4      multiple builders depending on the strategy you want to use to build the AMI.
     5  layout: docs
     6  page_title: 'Amazon AMI - Builders'
     7  sidebar_current: 'docs-builders-amazon'
     8  ---
     9  
    10  # Amazon AMI Builder
    11  
    12  Packer is able to create Amazon AMIs. To achieve this, Packer comes with
    13  multiple builders depending on the strategy you want to use to build the AMI.
    14  Packer supports the following builders at the moment:
    15  
    16  -   [amazon-ebs](/docs/builders/amazon-ebs.html) - Create EBS-backed AMIs by
    17      launching a source AMI and re-packaging it into a new AMI
    18      after provisioning. If in doubt, use this builder, which is the easiest to
    19      get started with.
    20  
    21  -   [amazon-instance](/docs/builders/amazon-instance.html) - Create
    22      instance-store AMIs by launching and provisioning a source instance, then
    23      rebundling it and uploading it to S3.
    24  
    25  -   [amazon-chroot](/docs/builders/amazon-chroot.html) - Create EBS-backed AMIs
    26      from an existing EC2 instance by mounting the root device and using a
    27      [Chroot](https://en.wikipedia.org/wiki/Chroot) environment to provision
    28      that device. This is an **advanced builder and should not be used by
    29      newcomers**. However, it is also the fastest way to build an EBS-backed AMI
    30      since no new EC2 instance needs to be launched.
    31  
    32  -   [amazon-ebssurrogate](/docs/builders/amazon-ebssurrogate.html) - Create EBS
    33      -backed AMIs from scratch. Works similarly to the `chroot` builder but does
    34      not require running in AWS. This is an **advanced builder and should not be
    35      used by newcomers**.
    36  
    37  -> **Don't know which builder to use?** If in doubt, use the [amazon-ebs
    38  builder](/docs/builders/amazon-ebs.html). It is much easier to use and Amazon
    39  generally recommends EBS-backed images nowadays.
    40  
    41  # Amazon EBS Volume Builder
    42  
    43  Packer is able to create Amazon EBS Volumes which are preinitialized with a
    44  filesystem and data.
    45  
    46  -   [amazon-ebsvolume](/docs/builders/amazon-ebsvolume.html) - Create EBS volumes
    47      by launching a source AMI with block devices mapped. Provision the instance,
    48      then destroy it, retaining the EBS volumes.
    49  
    50  <span id="specifying-amazon-credentials"></span>
    51  
    52  ## Specifying Amazon Credentials
    53  
    54  When you use any of the amazon builders, you must provide credentials to the API
    55  in the form of an access key id and secret. These look like:
    56  
    57      access key id:     AKIAIOSFODNN7EXAMPLE
    58      secret access key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
    59  
    60  If you use other AWS tools you may already have these configured. If so, packer
    61  will try to use them, *unless* they are specified in your packer template.
    62  Credentials are resolved in the following order:
    63  
    64  1.  Values hard-coded in the packer template are always authoritative.
    65  2.  *Variables* in the packer template may be resolved from command-line flags
    66      or from environment variables. Please read about [User
    67      Variables](https://www.packer.io/docs/templates/user-variables.html)
    68      for details.
    69  3.  If no credentials are found, packer falls back to automatic lookup.
    70  
    71  ### Automatic Lookup
    72  
    73  Packer depends on the [AWS
    74  SDK](https://aws.amazon.com/documentation/sdk-for-go/) to perform automatic
    75  lookup using *credential chains*. In short, the SDK looks for credentials in
    76  the following order:
    77  
    78  1.  Environment variables.
    79  2.  Shared credentials file.
    80  3.  If your application is running on an Amazon EC2 instance, IAM role for Amazon EC2.
    81  
    82  Please refer to the SDK's documentation on [specifying
    83  credentials](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials)
    84  for more information.
    85  
    86  ## Using an IAM Task or Instance Role
    87  
    88  If AWS keys are not specified in the template, a
    89  [shared credentials file](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-config-files)
    90  or through environment variables Packer will use credentials provided by
    91  the task's or instance's IAM role, if it has one.
    92  
    93  The following policy document provides the minimal set permissions necessary for
    94  Packer to work:
    95  
    96  ``` json
    97  {
    98    "Version": "2012-10-17",
    99    "Statement": [{
   100        "Effect": "Allow",
   101        "Action" : [
   102          "ec2:AttachVolume",
   103          "ec2:AuthorizeSecurityGroupIngress",
   104          "ec2:CopyImage",
   105          "ec2:CreateImage",
   106          "ec2:CreateKeypair",
   107          "ec2:CreateSecurityGroup",
   108          "ec2:CreateSnapshot",
   109          "ec2:CreateTags",
   110          "ec2:CreateVolume",
   111          "ec2:DeleteKeypair",
   112          "ec2:DeleteSecurityGroup",
   113          "ec2:DeleteSnapshot",
   114          "ec2:DeleteVolume",
   115          "ec2:DeregisterImage",
   116          "ec2:DescribeImageAttribute",
   117          "ec2:DescribeImages",
   118          "ec2:DescribeInstances",
   119          "ec2:DescribeRegions",
   120          "ec2:DescribeSecurityGroups",
   121          "ec2:DescribeSnapshots",
   122          "ec2:DescribeSubnets",
   123          "ec2:DescribeTags",
   124          "ec2:DescribeVolumes",
   125          "ec2:DetachVolume",
   126          "ec2:GetPasswordData",
   127          "ec2:ModifyImageAttribute",
   128          "ec2:ModifyInstanceAttribute",
   129          "ec2:ModifySnapshotAttribute",
   130          "ec2:RegisterImage",
   131          "ec2:RunInstances",
   132          "ec2:StopInstances",
   133          "ec2:TerminateInstances"
   134        ],
   135        "Resource" : "*"
   136    }]
   137  }
   138  ```
   139  
   140  ## Troubleshooting
   141  
   142  ### Attaching IAM Policies to Roles
   143  
   144  IAM policies can be associated with users or roles. If you use packer with IAM
   145  roles, you may encounter an error like this one:
   146  
   147      ==> amazon-ebs: Error launching source instance: You are not authorized to perform this operation.
   148  
   149  You can read more about why this happens on the [Amazon Security
   150  Blog](https://blogs.aws.amazon.com/security/post/Tx3M0IFB5XBOCQX/Granting-Permission-to-Launch-EC2-Instances-with-IAM-Roles-PassRole-Permission).
   151  The example policy below may help packer work with IAM roles. Note that this
   152  example provides more than the minimal set of permissions needed for packer to
   153  work, but specifics will depend on your use-case.
   154  
   155  ``` json
   156  {
   157      "Sid": "PackerIAMPassRole",
   158      "Effect": "Allow",
   159      "Action": "iam:PassRole",
   160      "Resource": [
   161          "*"
   162      ]
   163  }
   164  ```
   165  
   166  ### Checking that system time is current
   167  
   168  Amazon uses the current time as part of the [request signing
   169  process](http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html). If
   170  your system clock is too skewed from the current time, your requests might
   171  fail. If that's the case, you might see an error like this:
   172  
   173      ==> amazon-ebs: Error querying AMI: AuthFailure: AWS was not able to validate the provided access credentials
   174  
   175  If you suspect your system's date is wrong, you can compare it against
   176  <http://www.time.gov/>. On Linux/OS X, you can run the `date` command to get the
   177  current time. If you're on Linux, you can try setting the time with ntp by
   178  running `sudo ntpd -q`.