- Newest
- Most votes
- Most comments
Hello.
Looking at CloudTrail events, it appears that creation of the S3 bucket to store the CloudFormation template has failed.
So, why not try adding a policy for operating S3 as shown below?
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "SAMDeployCloudFormation",
"Effect": "Allow",
"Action": [
"cloudformation:CreateChangeSet",
"cloudformation:DescribeChangeSet",
"cloudformation:ExecuteChangeSet",
"cloudformation:DescribeStacks"
],
"Resource": [
"arn:aws:cloudformation:ap-south-1:<AccountID>:stack/aws-sam-cli-managed-default/*",
"arn:aws:cloudformation:ap-south-1:aws:transform/Serverless-2016-10-31"
]
},
{
"Sid": "SAMDeployCloudFormationFullAccess",
"Effect": "Allow",
"Action": "*",
"Resource": "*",
"Condition": {
"ArnLike": {
"aws:SourceArn": "arn:aws:cloudformation:ap-south-1:<AccountID>:stack/aws-sam-cli-managed-default/*"
}
}
},
{
"Sid": "S3",
"Effect": "Allow",
"Action": [
"s3:CreateBucket",
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket"
],
"Resource": "*"
}
]
}
Create a role that CloudFormation can assume, and attach to this role a permissions policy that contains sufficient privileges to create an S3 bucket.
In the CloudFormation template, specify the IAM role using the RoleARN property for the AWS::CloudFormation::Stack resource.
RoleARN: arn:aws:iam::<AccountID>:role/MyCloudFormationRole
How can I assign this role on SAM CLI to cloudformation?
I'm pretty new to it, so can you please share an example?
Please take a look at https://docs.aws.amazon.com/prescriptive-guidance/latest/least-privilege-cloudformation/service-roles-for-cloudformation.html
Where it offers the example:
to create a stack that contains an Amazon Elastic Compute Cloud (Amazon EC2) instance, the IAM principal would need to have permissions to create EC2 instances through their identity-based policy. Instead, CloudFormation can assume a service role that has permissions to create EC2 instances on the principal's behalf
Try to think in terms of permissions to create S3 buckets instead.
Relevant content
- AWS OFFICIALUpdated 4 months ago

The following document describes the policies required for S3 operations. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-template.html
Because it will grant the access to other user as well, who is using this role for developing the lambda function locally.
So, to them I only want to grant the required permissions(are there in this policy, but not included on re:post)
Also, if I'm granting the full access already to the service(aws-sam-cli-managed-default cloudformation stack) which is initiating the creation of S3 bucket during "SAM Deploy", then why do I need to again grant the permission?
I thought that since the ARN is "arn:aws:cloudformation:ap-south-1:<AccountID>:stack/aws-sam-cli-managed-default/*", this wouldn't allow S3 operations.
Can you please explain what do you mean by this?
Means is it the source issue(that it's not stack and something else)? Or Something else?
If it's source issue, what will be the right source that is generating the commands?
This is an IAM policy issue. At first glance, the policy below seems to allow full access, but the ARN is "arn:aws:cloudformation:ap-south-1:<AccountID>:stack/aws-sam-cli-managed-default/* ", so you cannot create or operate S3 with this.