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