hashicorp / hashicorp/packer-plugin-amazon

Error creating AMI: InvalidAMIName.Duplicate:

Open
#115 0 comments 1 reaction 0 assignees View on GitHub
bug help wanted question
Dominant language
Go
Stars
91
Forks
141
Avg merge
2d 18h
Merged PRs (30d)
3

Description

_This issue was originally opened by @Guy-Rawsthorn in https://github.com/hashicorp/packer/issues/11165 and has been migrated to this repository. The original issue description is below._

---
#### Overview

I have been seeing this issue intermittently and I can't work out if there's something wrong with my logic or a bug with packer.

I am using a timestamp function to give my AMI a unique ami_name.

**"ami_name": "{{user `ami_base_name`}}.{{timestamp}}",**

however, I am seeing the error below intermittently - This happens in around 1/3 of all builds.

Error creating AMI: InvalidAMIName.Duplicate: AMI name base.1627052837 is already in use by AMI ami-0f55d46062####\n status code: 400%!(PACKER_COMMA) request id: fea118ba-205e-4062-a790-bbb5e29a87fa

My understanding of the timestamp function would be to increment every second so it should be unique.

I have tripled checked there is no duplicate AMI within my AWS account.

#### Reproduction Steps

packer build base

### Packer version

packerVersion=1.7.4

### Simplified Packer Buildfile

{
"variables": {
"type": "",
"region": "{{env `AWS_DEFAULT_REGION`}}",
"instance_type": "",
"ssh_username": "",
"vpc_id": "",
"subnet_id": "",
"iam_instance_profile": "",
"base_ami": "{{env `AMI_AMAZON_LINUX`}}",
"ami_base_name": "",
"branch": "{{env `BRANCH_NAME`}}",
"commit": "{{env `GIT_COMMIT`}}"
},
"builders": [
{
"type": "amazon-ebs",
"region": "{{user `region`}}",
"source_ami": "{{user `base_ami`}}",
"instance_type": "{{user `instance_type`}}",
"ssh_username": "{{user `ssh_username`}}",
"ssh_keypair_name": "{{user `ssh_keypair_name`}}",
"ssh_agent_auth": "{{user `ssh_agent_auth`}}",
"ssh_interface": "private_ip",
**"ami_name": "{{user `ami_base_name`}}.{{timestamp}}",**
"ami_description": "Base image that can be used for building and testing",
"vpc_id": "{{user `vpc_id`}}",
"subnet_id": "{{user `subnet_id`}}",
"security_group_ids": "{{user `security_group_ids`}}",
"iam_instance_profile": "{{user `iam_instance_profile`}}",
"enable_t2_unlimited": false,
"run_tags": {
"Name": "packer-builder:{{user `ami_base_name`}}",
"Repo": "{{user `repo_name`}}",
"Branch": "{{user `branch`}}",
"Commit": "{{user `commit`}}"
},
"tags": {
"Name": "{{user `ami_base_name`}}",
"Repo": "{{user `repo_name`}}",
"Branch": "{{user `branch`}}",
"Commit": "{{user `commit`}}"
},
"ssh_timeout": "5m"
}
],
"provisioners": [
{
"type": "shell",
"execute_command": "chmod +x {{.Path}}; {{.Vars}} sudo -E -S bash -x '{{.Path}}'",
"script": "setup.sh"
}
],
"post-processors": [
{
"type": "manifest",
"output": "manifest.json",
"strip_path": true,
"custom_data": {
"ami_base_name": "{{user `ami_base_name`}}"
}
}
]
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.