github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/website/source/docs/builders/amazon-ebs.html.md (about) 1 --- 2 description: | 3 The `amazon-ebs` Packer builder is able to create Amazon AMIs backed by EBS 4 volumes for use in EC2. For more information on the difference between 5 EBS-backed instances and instance-store backed instances, see the storage for 6 the root device section in the EC2 documentation. 7 layout: docs 8 page_title: 'Amazon AMI Builder (EBS backed)' 9 ... 10 11 # AMI Builder (EBS backed) 12 13 Type: `amazon-ebs` 14 15 The `amazon-ebs` Packer builder is able to create Amazon AMIs backed by EBS 16 volumes for use in [EC2](https://aws.amazon.com/ec2/). For more information on 17 the difference between EBS-backed instances and instance-store backed instances, 18 see the ["storage for the root device" section in the EC2 19 documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ComponentsAMIs.html#storage-for-the-root-device). 20 21 This builder builds an AMI by launching an EC2 instance from a source AMI, 22 provisioning that running machine, and then creating an AMI from that machine. 23 This is all done in your own AWS account. The builder will create temporary 24 keypairs, security group rules, etc. that provide it temporary access to the 25 instance while the image is being created. This simplifies configuration quite a 26 bit. 27 28 The builder does *not* manage AMIs. Once it creates an AMI and stores it in your 29 account, it is up to you to use, delete, etc. the AMI. 30 31 ## Configuration Reference 32 33 There are many configuration options available for the builder. They are 34 segmented below into two categories: required and optional parameters. Within 35 each category, the available configuration keys are alphabetized. 36 37 In addition to the options listed here, a 38 [communicator](/docs/templates/communicator.html) can be configured for this 39 builder. 40 41 ### Required: 42 43 - `access_key` (string) - The access key used to communicate with AWS. [Learn 44 how to set this.](/docs/builders/amazon.html#specifying-amazon-credentials) 45 46 - `ami_name` (string) - The name of the resulting AMI that will appear when 47 managing AMIs in the AWS console or via APIs. This must be unique. To help 48 make this unique, use a function like `timestamp` (see [configuration 49 templates](/docs/templates/configuration-templates.html) for more info) 50 51 - `instance_type` (string) - The EC2 instance type to use while building the 52 AMI, such as `m1.small`. 53 54 - `region` (string) - The name of the region, such as `us-east-1`, in which to 55 launch the EC2 instance to create the AMI. 56 57 - `secret_key` (string) - The secret key used to communicate with AWS. [Learn 58 how to set this.](/docs/builders/amazon.html#specifying-amazon-credentials) 59 60 - `source_ami` (string) - The initial AMI used as a base for the newly 61 created machine. `source_ami_filter` may be used instead to populate this 62 automatically. 63 64 ### Optional: 65 66 - `ami_block_device_mappings` (array of block device mappings) - Add the block 67 device mappings to the AMI. The block device mappings allow for keys: 68 69 - `delete_on_termination` (boolean) - Indicates whether the EBS volume is 70 deleted on instance termination. Default `false`. **NOTE**: If this 71 value is not explicitly set to `true` and volumes are not cleaned up by 72 an alternative method, additional volumes will accumulate after 73 every build. 74 75 - `device_name` (string) - The device name exposed to the instance (for 76 example, `/dev/sdh` or `xvdh`). Required when specifying `volume_size`. 77 78 - `encrypted` (boolean) - Indicates whether to encrypt the volume or not 79 80 - `iops` (integer) - The number of I/O operations per second (IOPS) that the 81 volume supports. See the documentation on 82 [IOPs](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EbsBlockDevice.html) 83 for more information 84 85 - `no_device` (boolean) - Suppresses the specified device included in the 86 block device mapping of the AMI 87 88 - `snapshot_id` (string) - The ID of the snapshot 89 90 - `virtual_name` (string) - The virtual device name. See the documentation on 91 [Block Device 92 Mapping](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_BlockDeviceMapping.html) 93 for more information 94 95 - `volume_size` (integer) - The size of the volume, in GiB. Required if not 96 specifying a `snapshot_id` 97 98 - `volume_type` (string) - The volume type. `gp2` for General Purpose (SSD) 99 volumes, `io1` for Provisioned IOPS (SSD) volumes, and `standard` for Magnetic 100 volumes 101 102 - `ami_description` (string) - The description to set for the 103 resulting AMI(s). By default this description is empty. 104 105 - `ami_groups` (array of strings) - A list of groups that have access to 106 launch the resulting AMI(s). By default no groups have permission to launch 107 the AMI. `all` will make the AMI publicly accessible. AWS currently doesn't 108 accept any value other than `all`. 109 110 - `ami_product_codes` (array of strings) - A list of product codes to 111 associate with the AMI. By default no product codes are associated with 112 the AMI. 113 114 - `ami_regions` (array of strings) - A list of regions to copy the AMI to. 115 Tags and attributes are copied along with the AMI. AMI copying takes time 116 depending on the size of the AMI, but will generally take many minutes. 117 118 - `ami_users` (array of strings) - A list of account IDs that have access to 119 launch the resulting AMI(s). By default no additional users other than the 120 user creating the AMI has permissions to launch it. 121 122 - `ami_virtualization_type` (string) - The type of virtualization for the AMI 123 you are building. This option must match the supported virtualization 124 type of `source_ami`. Can be `paravirtual` or `hvm`. 125 126 - `associate_public_ip_address` (boolean) - If using a non-default VPC, public 127 IP addresses are not provided by default. If this is toggled, your new 128 instance will get a Public IP. 129 130 - `availability_zone` (string) - Destination availability zone to launch 131 instance in. Leave this empty to allow Amazon to auto-assign. 132 133 - `disable_stop_instance` (boolean) - Packer normally stops the build instance 134 after all provisioners have run. For Windows instances, it is sometimes 135 desirable to [run Sysprep](http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ami-create-standard.html) 136 which will stop the instance for you. If this is set to true, Packer *will not* 137 stop the instance and will wait for you to stop it manually. You can do this 138 with a [windows-shell provisioner](https://www.packer.io/docs/provisioners/windows-shell.html). 139 140 ``` {.javascript} 141 { 142 "type": "windows-shell", 143 "inline": ["\"c:\\Program Files\\Amazon\\Ec2ConfigService\\ec2config.exe\" -sysprep"] 144 } 145 ``` 146 147 - `ebs_optimized` (boolean) - Mark instance as [EBS 148 Optimized](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSOptimized.html). 149 Default `false`. 150 151 - `enhanced_networking` (boolean) - Enable enhanced 152 networking (SriovNetSupport) on HVM-compatible AMIs. If true, add 153 `ec2:ModifyInstanceAttribute` to your AWS IAM policy. 154 155 - `force_deregister` (boolean) - Force Packer to first deregister an existing 156 AMI if one with the same name already exists. Default `false`. 157 158 - `force_delete_snapshot` (boolean) - Force Packer to delete snapshots associated with 159 AMIs, which have been deregistered by `force_deregister`. Default `false`. 160 161 - `encrypt_boot` (boolean) - Instruct packer to automatically create a copy of the 162 AMI with an encrypted boot volume (discarding the initial unencrypted AMI in the 163 process). Default `false`. 164 165 - `kms_key_id` (string) - The ID of the KMS key to use for boot volume encryption. 166 This only applies to the main `region`, other regions where the AMI will be copied 167 will be encrypted by the default EBS KMS key. 168 169 - `iam_instance_profile` (string) - The name of an [IAM instance 170 profile](https://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html) 171 to launch the EC2 instance with. 172 173 - `launch_block_device_mappings` (array of block device mappings) - Add the 174 block device mappings to the launch instance. The block device mappings are 175 the same as `ami_block_device_mappings` above. 176 177 - `run_tags` (object of key/value strings) - Tags to apply to the instance 178 that is *launched* to create the AMI. These tags are *not* applied to the 179 resulting AMI unless they're duplicated in `tags`. 180 181 - `run_volume_tags` (object of key/value strings) - Tags to apply to the volumes 182 that are *launched* to create the AMI. These tags are *not* applied to the 183 resulting AMI unless they're duplicated in `tags`. 184 185 - `security_group_id` (string) - The ID (*not* the name) of the security group 186 to assign to the instance. By default this is not set and Packer will 187 automatically create a new temporary security group to allow SSH access. 188 Note that if this is specified, you must be sure the security group allows 189 access to the `ssh_port` given below. 190 191 - `security_group_ids` (array of strings) - A list of security groups as 192 described above. Note that if this is specified, you must omit the 193 `security_group_id`. 194 195 - `shutdown_behavior` (string) - Automatically terminate instances on shutdown 196 incase packer exits ungracefully. Possible values are "stop" and "terminate", 197 default is `stop`. 198 199 - `skip_region_validation` (boolean) - Set to true if you want to skip 200 validation of the region configuration option. Default `false`. 201 202 - `snapshot_groups` (array of strings) - A list of groups that have access to 203 create volumes from the snapshot(s). By default no groups have permission to create 204 volumes form the snapshot(s). `all` will make the snapshot publicly accessible. 205 206 - `snapshot_users` (array of strings) - A list of account IDs that have access to 207 create volumes from the snapshot(s). By default no additional users other than the 208 user creating the AMI has permissions to create volumes from the backing snapshot(s). 209 210 - `snapshot_tags` (object of key/value strings) - Tags to apply to snapshot. 211 They will override AMI tags if already applied to snapshot. 212 213 - `source_ami_filter` (object) - Filters used to populate the `source_ami` field. 214 Example: 215 216 ``` {.javascript} 217 "source_ami_filter": { 218 "filters": { 219 "virtualization-type": "hvm", 220 "name": "*ubuntu-xenial-16.04-amd64-server-*", 221 "root-device-type": "ebs" 222 }, 223 "owners": ["099720109477"], 224 "most_recent": true 225 } 226 ``` 227 228 This selects the most recent Ubuntu 16.04 HVM EBS AMI from Canonical. 229 NOTE: This will fail unless *exactly* one AMI is returned. In the above 230 example, `most_recent` will cause this to succeed by selecting the newest image. 231 232 - `filters` (map of strings) - filters used to select a `source_ami`. 233 NOTE: This will fail unless *exactly* one AMI is returned. 234 Any filter described in the docs for [DescribeImages](http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImages.html) 235 is valid. 236 237 - `owners` (array of strings) - This scopes the AMIs to certain Amazon account IDs. 238 This is helpful to limit the AMIs to a trusted third party, or to your own account. 239 240 - `most_recent` (bool) - Selects the newest created image when true. 241 This is most useful for selecting a daily distro build. 242 243 - `spot_price` (string) - The maximum hourly price to pay for a spot instance 244 to create the AMI. Spot instances are a type of instance that EC2 starts 245 when the current spot price is less than the maximum price you specify. Spot 246 price will be updated based on available spot instance capacity and current 247 spot instance requests. It may save you some costs. You can set this to 248 `auto` for Packer to automatically discover the best spot price or to "0" 249 to use an on demand instance (default). 250 251 - `spot_price_auto_product` (string) - Required if `spot_price` is set 252 to `auto`. This tells Packer what sort of AMI you're launching to find the 253 best spot price. This must be one of: `Linux/UNIX`, `SUSE Linux`, `Windows`, 254 `Linux/UNIX (Amazon VPC)`, `SUSE Linux (Amazon VPC)`, `Windows (Amazon VPC)` 255 256 - `ssh_keypair_name` (string) - If specified, this is the key that will be 257 used for SSH with the machine. The key must match a key pair name loaded 258 up into Amazon EC2. By default, this is blank, and Packer will 259 generate a temporary keypair unless 260 [`ssh_password`](/docs/templates/communicator.html#ssh_password) is used. 261 [`ssh_private_key_file`](/docs/templates/communicator.html#ssh_private_key_file) 262 or `ssh_agent_auth` must be specified when `ssh_keypair_name` is utilized. 263 264 - `ssh_agent_auth` (boolean) - If true, the local SSH agent will be used to 265 authenticate connections to the source instance. No temporary keypair will 266 be created, and the values of `ssh_password` and `ssh_private_key_file` will 267 be ignored. To use this option with a key pair already configured in the source 268 AMI, leave the `ssh_keypair_name` blank. To associate an existing key pair 269 in AWS with the source instance, set the `ssh_keypair_name` field to the name 270 of the key pair. 271 272 - `ssh_private_ip` (boolean) - If true, then SSH will always use the private 273 IP if available. 274 275 - `subnet_id` (string) - If using VPC, the ID of the subnet, such as 276 `subnet-12345def`, where Packer will launch the EC2 instance. This field is 277 required if you are using an non-default VPC. 278 279 - `tags` (object of key/value strings) - Tags applied to the AMI and 280 relevant snapshots. 281 282 - `temporary_key_pair_name` (string) - The name of the temporary keypair 283 to generate. By default, Packer generates a name with a UUID. 284 285 - `token` (string) - The access token to use. This is different from the 286 access key and secret key. If you're not sure what this is, then you 287 probably don't need it. This will also be read from the `AWS_SESSION_TOKEN` 288 environmental variable. 289 290 - `user_data` (string) - User data to apply when launching the instance. Note 291 that you need to be careful about escaping characters due to the templates 292 being JSON. It is often more convenient to use `user_data_file`, instead. 293 294 - `user_data_file` (string) - Path to a file that will be used for the user 295 data when launching the instance. 296 297 - `vpc_id` (string) - If launching into a VPC subnet, Packer needs the VPC ID 298 in order to create a temporary security group within the VPC. Requires `subnet_id` 299 to be set. 300 301 - `windows_password_timeout` (string) - The timeout for waiting for a Windows 302 password for Windows instances. Defaults to 20 minutes. Example value: `10m` 303 304 ## Basic Example 305 306 Here is a basic example. You will need to provide access keys, and may need to change the AMI IDs according to what images exist at the time the template is run: 307 308 ``` {.javascript} 309 { 310 "type": "amazon-ebs", 311 "access_key": "YOUR KEY HERE", 312 "secret_key": "YOUR SECRET KEY HERE", 313 "region": "us-east-1", 314 "source_ami": "ami-fce3c696", 315 "instance_type": "t2.micro", 316 "ssh_username": "ubuntu", 317 "ami_name": "packer-quick-start {{timestamp}}" 318 } 319 ``` 320 321 -> **Note:** Packer can also read the access key and secret access key from 322 environmental variables. See the configuration reference in the section above 323 for more information on what environmental variables Packer will look for. 324 325 Further information on locating AMI IDs and their relationship to instance types and regions can be found in the AWS EC2 Documentation [for Linux](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/finding-an-ami.html) or [for Windows](http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/finding-an-ami.html). 326 327 ## Accessing the Instance to Debug 328 329 If you need to access the instance to debug for some reason, run the builder 330 with the `-debug` flag. In debug mode, the Amazon builder will save the private 331 key in the current directory and will output the DNS or IP information as well. 332 You can use this information to access the instance as it is running. 333 334 ## AMI Block Device Mappings Example 335 336 Here is an example using the optional AMI block device mappings. This will add 337 the /dev/sdb and /dev/sdc block device mappings to the finished AMI. As with the basic example, you will need to provide access keys and may need to change the source AMI ID based on what images exist when this template is run: 338 339 ``` {.javascript} 340 { 341 "type": "amazon-ebs", 342 "access_key": "YOUR KEY HERE", 343 "secret_key": "YOUR SECRET KEY HERE", 344 "region": "us-east-1", 345 "source_ami": "ami-fce3c696", 346 "instance_type": "t2.micro", 347 "ssh_username": "ubuntu", 348 "ami_name": "packer-quick-start {{timestamp}}", 349 "ami_block_device_mappings": [ 350 { 351 "device_name": "/dev/sdb", 352 "virtual_name": "ephemeral0" 353 }, 354 { 355 "device_name": "/dev/sdc", 356 "virtual_name": "ephemeral1" 357 } 358 ] 359 } 360 ``` 361 362 ## Tag Example 363 364 Here is an example using the optional AMI tags. This will add the tags 365 "OS\_Version" and "Release" to the finished AMI. As before, you will need to provide your access keys, and may need to change the source AMI ID based on what images exist when this template is run: 366 367 ``` {.javascript} 368 { 369 "type": "amazon-ebs", 370 "access_key": "YOUR KEY HERE", 371 "secret_key": "YOUR SECRET KEY HERE", 372 "region": "us-east-1", 373 "source_ami": "ami-fce3c696", 374 "instance_type": "t2.micro", 375 "ssh_username": "ubuntu", 376 "ami_name": "packer-quick-start {{timestamp}}", 377 "tags": { 378 "OS_Version": "Ubuntu", 379 "Release": "Latest" 380 } 381 } 382 ``` 383 384 -> **Note:** Packer uses pre-built AMIs as the source for building images. 385 These source AMIs may include volumes that are not flagged to be destroyed on 386 termination of the instance building the new image. Packer will attempt to clean 387 up all residual volumes that are not designated by the user to remain after 388 termination. If you need to preserve those source volumes, you can overwrite the 389 termination setting by specifying `delete_on_termination=false` in the 390 `launch_block_device_mappings` block for the device.