github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/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 use the environment variables 36 `AWS_ACCESS_KEY_ID` or `AWS_ACCESS_KEY` (in that order), if set. 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 use the environment variables 51 `AWS_SECRET_ACCESS_KEY` or `AWS_SECRET_KEY` (in that order), if set. 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" (integer), "delete\_on\_termination" 65 (boolean), "encrypted" (boolean), "no\_device" (boolean), and "iops" 66 (integer). 67 68 * `ami_description` (string) - The description to set for the resulting 69 AMI(s). By default this description is empty. 70 71 * `ami_groups` (array of strings) - A list of groups that have access 72 to launch the resulting AMI(s). By default no groups have permission 73 to launch the AMI. `all` will make the AMI publicly accessible. 74 75 * `ami_product_codes` (array of strings) - A list of product codes to 76 associate with the AMI. By default no product codes are associated with 77 the AMI. 78 79 * `ami_regions` (array of strings) - A list of regions to copy the AMI to. 80 Tags and attributes are copied along with the AMI. AMI copying takes time 81 depending on the size of the AMI, but will generally take many minutes. 82 83 * `ami_users` (array of strings) - A list of account IDs that have access 84 to launch the resulting AMI(s). By default no additional users other than the user 85 creating the AMI has permissions to launch it. 86 87 * `ami_virtualization_type` (string) - The type of virtualization for the AMI 88 you are building. This option is required to register HVM images. Can be 89 "paravirtual" (default) or "hvm". 90 91 * `associate_public_ip_address` (boolean) - If using a non-default VPC, public 92 IP addresses are not provided by default. If this is toggled, your new 93 instance will get a Public IP. 94 95 * `availability_zone` (string) - Destination availability zone to launch instance in. 96 Leave this empty to allow Amazon to auto-assign. 97 98 * `enhanced_networking` (boolean) - Enable enhanced networking (SriovNetSupport) on 99 HVM-compatible AMIs. 100 101 * `iam_instance_profile` (string) - The name of an 102 [IAM instance profile](http://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html) 103 to launch the EC2 instance with. 104 105 * `launch_block_device_mappings` (array of block device mappings) - Add the 106 block device mappings to the launch instance. The block device mappings are 107 the same as `ami_block_device_mappings` above. 108 109 * `run_tags` (object of key/value strings) - Tags to apply to the instance 110 that is _launched_ to create the AMI. These tags are _not_ applied to 111 the resulting AMI unless they're duplicated in `tags`. 112 113 * `security_group_id` (string) - The ID (_not_ the name) of the security 114 group to assign to the instance. By default this is not set and Packer 115 will automatically create a new temporary security group to allow SSH 116 access. Note that if this is specified, you must be sure the security 117 group allows access to the `ssh_port` given below. 118 119 * `security_group_ids` (array of strings) - A list of security groups as 120 described above. Note that if this is specified, you must omit the 121 `security_group_id`. 122 123 * `spot_price` (string) - The maximum hourly price to launch a spot instance 124 to create the AMI. It is a type of instances that EC2 starts when the maximum 125 price that you specify exceeds the current spot price. Spot price will be 126 updated based on available spot instance capacity and current spot Instance 127 requests. It may save you some costs. You can set this to "auto" for 128 Packer to automatically discover the best spot price. 129 130 * `spot_price_auto_product` (string) - Required if `spot_price` is set to 131 "auto". This tells Packer what sort of AMI you're launching to find the best 132 spot price. This must be one of: `Linux/UNIX`, `SUSE Linux`, `Windows`, 133 `Linux/UNIX (Amazon VPC)`, `SUSE Linux (Amazon VPC)`, `Windows (Amazon VPC)` 134 135 * `ssh_port` (integer) - The port that SSH will be available on. This defaults 136 to port 22. 137 138 * `ssh_private_key_file` (string) - Use this ssh private key file instead of 139 a generated ssh key pair for connecting to the instance. 140 141 * `ssh_private_ip` (bool) - If true, then SSH will always use the private 142 IP if available. 143 144 * `ssh_timeout` (string) - The time to wait for SSH to become available 145 before timing out. The format of this value is a duration such as "5s" 146 or "5m". The default SSH timeout is "5m", or five minutes. 147 148 * `subnet_id` (string) - If using VPC, the ID of the subnet, such as 149 "subnet-12345def", where Packer will launch the EC2 instance. 150 151 * `tags` (object of key/value strings) - Tags applied to the AMI. 152 153 * `temporary_key_pair_name` (string) - The name of the temporary keypair 154 to generate. By default, Packer generates a name with a UUID. 155 156 * `token` (string) - The access token to use. This is different from 157 the access key and secret key. If you're not sure what this is, then you 158 probably don't need it. This will also be read from the `AWS_SECURITY_TOKEN` 159 environmental variable. 160 161 * `user_data` (string) - User data to apply when launching the instance. 162 Note that you need to be careful about escaping characters due to the 163 templates being JSON. It is often more convenient to use `user_data_file`, 164 instead. 165 166 * `user_data_file` (string) - Path to a file that will be used for the 167 user data when launching the instance. 168 169 * `vpc_id` (string) - If launching into a VPC subnet, Packer needs the 170 VPC ID in order to create a temporary security group within the VPC. 171 172 ## Basic Example 173 174 Here is a basic example. It is completely valid except for the access keys: 175 176 <pre class="prettyprint"> 177 { 178 "type": "amazon-ebs", 179 "access_key": "YOUR KEY HERE", 180 "secret_key": "YOUR SECRET KEY HERE", 181 "region": "us-east-1", 182 "source_ami": "ami-de0d9eb7", 183 "instance_type": "t1.micro", 184 "ssh_username": "ubuntu", 185 "ami_name": "packer-quick-start {{timestamp}}" 186 } 187 </pre> 188 189 <div class="alert alert-block alert-info"> 190 <strong>Note:</strong> Packer can also read the access key and secret 191 access key from environmental variables. See the configuration reference in 192 the section above for more information on what environmental variables Packer 193 will look for. 194 </div> 195 196 ## Accessing the Instance to Debug 197 198 If you need to access the instance to debug for some reason, run the builder 199 with the `-debug` flag. In debug mode, the Amazon builder will save the 200 private key in the current directory and will output the DNS or IP information 201 as well. You can use this information to access the instance as it is 202 running. 203 204 ## AMI Block Device Mappings Example 205 206 Here is an example using the optional AMI block device mappings. This will add 207 the /dev/sdb and /dev/sdc block device mappings to the finished AMI. 208 209 <pre class="prettyprint"> 210 { 211 "type": "amazon-ebs", 212 "access_key": "YOUR KEY HERE", 213 "secret_key": "YOUR SECRET KEY HERE", 214 "region": "us-east-1", 215 "source_ami": "ami-de0d9eb7", 216 "instance_type": "t1.micro", 217 "ssh_username": "ubuntu", 218 "ami_name": "packer-quick-start {{timestamp}}", 219 "ami_block_device_mappings": [ 220 { 221 "device_name": "/dev/sdb", 222 "virtual_name": "ephemeral0" 223 }, 224 { 225 "device_name": "/dev/sdc", 226 "virtual_name": "ephemeral1" 227 } 228 ] 229 } 230 </pre> 231 232 ## Tag Example 233 234 Here is an example using the optional AMI tags. This will add the tags 235 "OS_Version" and "Release" to the finished AMI. 236 237 <pre class="prettyprint"> 238 { 239 "type": "amazon-ebs", 240 "access_key": "YOUR KEY HERE", 241 "secret_key": "YOUR SECRET KEY HERE", 242 "region": "us-east-1", 243 "source_ami": "ami-de0d9eb7", 244 "instance_type": "t1.micro", 245 "ssh_username": "ubuntu", 246 "ami_name": "packer-quick-start {{timestamp}}", 247 "tags": { 248 "OS_Version": "Ubuntu", 249 "Release": "Latest" 250 } 251 } 252 </pre>