Packer: No valid AWS authentication found

I’ve been following the tutorial at http://www.packer.io/intro/getting-started/build-image.html.

I validated the JSON, signed up for an AWS account and set up an IAM with administrative rights and yet, on running the command to build the AMI, I received errors:

$ env AWS_ACCESS_KEY=key SECRET_KEY=secret packer build example.json
amazon-ebs output will be in this color.

Build 'amazon-ebs' errored: No valid AWS authentication found

==> Some builds didn't complete successfully and had errors:
--> amazon-ebs: No valid AWS authentication found

==> Builds finished but no artifacts were created.

The fix that worked for me was to download and install the AWS CLI toolhttp://docs.aws.amazon.com/cli/latest/usergui…, run aws configure and fill out the access key, secret key, and region name fields. Once I’d done that I ran aws ec2 describe-instances. I don’t have any instances so the response was an empty list, but it meant that when I ran the packer command again, it worked.

This could be because AWS needed a first time good connection for whatever reason, or that there was now a ~/.aws folder with a configuration to be read. Either way, that fixed it - onwards and upwards!

Added on:
Info:- Packer v0.7.5 - aws-cli/1.7.38 - Python/3.4.2