Hello,
We are using packer with a build.pkr.hcl file to build an AWS AMI EC2 image based on the AWS Amazon Linux 2023 (not Amazon Linux 2).
The build block is:
build {
sources = ["source.amazon-ebs.vf_pcs_al2023_eks"]
provisioner "shell" {
inline = [
"echo 'Sleeping for 30 seconds to give the AMIs enough time to initialize (otherwise, packages may fail to install).'",
"sleep 30",
"echo 'Installing AWS CLI'",
"sudo yum update -y && sudo yum install -y aws-cli unzip perl-Digest-SHA jq"
]
remote_folder = "/home/ec2-user/.cache"
}
When we execute the build.pkr.hcl we get the error:
null_resource.packer_build: Still creating… [2m20s elapsed]
null_resource.packer_build (local-exec): amazon-ebs.vf_pcs_al2023_eks: Port 8833 opened for sessionId i-02a…0561-pvepujtqkk2c2z3exlxhvcfpiq.
null_resource.packer_build (local-exec): amazon-ebs.vf_pcs_al2023_eks: Waiting for connections…
null_resource.packer_build (local-exec): amazon-ebs.vf_pcs_al2023_eks: Connection accepted for session [i-02a…0561-pvepujtqkk2c2z3exlxhvcfpiq]
null_resource.packer_build (local-exec): ==> amazon-ebs.vf_pcs_al2023_eks: Connected to SSH!
null_resource.packer_build (local-exec): ==> amazon-ebs.vf_pcs_al2023_eks: Provisioning with shell script: /tmp/packer-shell1109162450
null_resource.packer_build (local-exec): ==> amazon-ebs.vf_pcs_al2023_eks: chmod: cannot access ‘/home/ec2-user/.cache/script_3273.sh’: Not a directory
null_resource.packer_build (local-exec): ==> amazon-ebs.vf_pcs_al2023_eks: bash: line 1: /home/ec2-user/.cache/script_3273.sh: Not a directory
I launched a test EC2 instance with AL2023 and indeed there is no .cache directory in the /home/ec2-user/ anymore. I checked in an EC2 instance with AL2 from 2024 and there is a .cache directory in /home/ec2-user/ .
I added the line to create this directory:
provisioner "shell" {
inline = [
"echo 'Sleeping for 30 seconds to give the AMIs enough time to initialize (otherwise, packages may fail to install).'",
"sleep 30",
"mkdir /home/${var.ec2_user_source}/.cache",
But it seems the packer build block wants to run /home/ec2-user/.cache/script_3273.sh before the inline bash script from the provisioner “shell” inline block.
The remote_folder is set to "/home/ec2-user/.cache" as you can see in the build block above.
Will changing the remote_folder to /home/ec2-user/ will help in this case?
PS: At this moment I am not sure whether the /home/ec2-user/.cache directory was removed in AL2023 or it is created by our internal AMI team which is responsabile for AMI hardening. I will confirm with them.
Thank you.