packer-plugin-amazon icon indicating copy to clipboard operation
packer-plugin-amazon copied to clipboard

packer build amazon-instance Error talking to S3

Open hc-github-team-packer opened this issue 3 years ago • 0 comments

This issue was originally opened by @PAKalucki in https://github.com/hashicorp/packer/issues/11887 and has been migrated to this repository. The original issue description is below.


Overview of the Issue

Packer build of amazon-instance fails on upload with:

instance_ami.amazon-instance.ubuntu: ERROR: Error talking to S3: Server.InvalidRequest(400): The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.

Reproduction Steps

Run packer build with template below, with ubuntu 20.04 focal source_ami

Packer version

1.8.2

Simplified Packer Template

packer {
  required_plugins {
    amazon = {
      source  = "github.com/hashicorp/amazon"
      version = ">= 1.1.1"
    }
  }
}

source "amazon-instance" "ubuntu" {
  ami_name       = "instance_ami"
  instance_type  = "t2.micro"
  region         = "eu-central-1"
  source_ami     = "ami"
  account_id     = "xxx"
  s3_bucket      = "bucket"
  x509_cert_path = "certificate.pem"
  x509_key_path  = "private-key.pem"
  ssh_username   = "ubuntu"
  bundle_upload_command = "sudo -i -n ec2-upload-bundle -b {{.BucketName}} -m {{.ManifestPath}} -a {{.AccessKey}} -s {{.SecretKey}} -d {{.BundleDirectory}} --location {{.Region}} --batch --retry"

  temporary_iam_instance_profile_policy_document {
    Version = "2012-10-17"
    Statement {
        Effect = "Allow"
        Action = [
          "s3:PutObject",
          "s3:GetObject",
          "s3:ListBucket",
          "s3:GetBucketLocation",
          "s3:PutObjectAcl"
        ]
        Resource = ["*"]
    }
  }
}

build {
  name = "instance_ami"
  sources = [
    "source.amazon-instance.ubuntu"
  ]

  provisioner "shell" {
    inline = ["sudo apt-get update -y && sudo apt-get install ec2-ami-tools"]
  }
}

Log Fragments and crash.log files

==> instance_ami.amazon-instance.ubuntu: Uploading the bundle...
==> instance_ami.amazon-instance.ubuntu: ERROR: Error talking to S3: Server.InvalidRequest(400): The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.
==> instance_ami.amazon-instance.ubuntu: Please check that the bucket `bucket` does not exist, or exists and is writable. This error indicates that the bucket may be owned by somebody else.
==> instance_ami.amazon-instance.ubuntu: Bundle upload failed. Please see the output above for more
==> instance_ami.amazon-instance.ubuntu: details on what went wrong.
==> instance_ami.amazon-instance.ubuntu: Provisioning step had errors: Running the cleanup provisioner, if present...
==> instance_ami.amazon-instance.ubuntu: Terminating the source AWS instance...
==> instance_ami.amazon-instance.ubuntu: Detaching temporary role from instance profile...
==> instance_ami.amazon-instance.ubuntu: Removing policy from temporary role...
==> instance_ami.amazon-instance.ubuntu: Deleting temporary role...
==> instance_ami.amazon-instance.ubuntu: Deleting temporary instance profile...
==> instance_ami.amazon-instance.ubuntu: Deleting temporary security group...
==> instance_ami.amazon-instance.ubuntu: Deleting temporary keypair...
Build 'instance_ami.amazon-instance.ubuntu' errored after 7 minutes 52 seconds: Bundle upload failed. Please see the output above for more
details on what went wrong.

==> Wait completed after 7 minutes 52 seconds

==> Some builds didn't complete successfully and had errors:
--> instance_ami.amazon-instance.ubuntu: Bundle upload failed. Please see the output above for more
details on what went wrong.

==> Builds finished but no artifacts were created.

hc-github-team-packer avatar Jul 27 '22 01:07 hc-github-team-packer