I have a CloudFormation script that uses an AWS::CloudFormation::Init
section to download a file from an S3 bucket which fails with Access Denied (403).
I have added an IAM role named s3access
to the machine using an AWS::IAM::InstanceProfile
. Downloading the file with aws s3
works:
[ec2-user@ip-172-31-26-26 ~]$ aws s3 cp s3://my-bucket/test-file
.download: s3://my-bucket/test-file to ./test-file
But cfn-init
fails:
[ec2-user@ip-172-31-26-26 ~]$ sudo /opt/aws/bin/cfn-init -v --stack test --resource EC2 --region us-east-2 Error occurred during build: Failed to retrieve https://s3.us-east-2.amazonaws.com/my-bucket/test-file: HTTP Error 403 :
I tried setting the IAM role explicitly but that fails too:
[ec2-user@ip-172-31-26-26 ~]$ sudo /opt/aws/bin/cfn-init -v --stack test --resource EC2 --region us-east-2 --role=s3access AccessDenied: User: arn:aws:sts::196375698259:assumed-role/s3access/i-044499612c92b50f5 is not authorized to perform: cloudformation:DescribeStackResource on resource: arn:aws:cloudformation:us-east-2:196375698259:stack/test/*
I'm thinking of using aws s3 cp s3://my-bucket/test-file ./
directly from the user-data but I'd like to know why the AWS::CloudFormation::Init
fails to assume the role assigned to the EC2 instance.
I found only one similar question - How can I access protected S3 files in a CFN script?, but the solution there is to apply an IAM role, which I have already done and cfn-init
still fails.