87

I'm trying out Serverless to create AWS Lambdas and while creating a project using the command serverless project create I'm getting the following error.

AccessDenied: User: arn:aws:iam::XXXXXXXXX:user/XXXXXXXXX is not authorized to perform: cloudformation:CreateStack on resource: arn:aws:cloudformation:us-east-1:XXXXXXXXX:stack/XXXXXXXXX-development-r/*

I have created a user and granted the following permissions to the user.

  1. AWSLambdaFullAccess
  2. AmazonS3FullAccess
  3. CloudFrontFullAccess
  4. AWSCloudFormationReadOnlyAccess ( There was no AWSCloudFormationFullAccess to grant )

How can I proceed? What else permissions I have to grant?

Milindu Sanoj Kumarage
  • 2,714
  • 2
  • 31
  • 54

11 Answers11

106

The closest one that you've mentioned is AWSCloudFormationReadOnlyAccess, but obviously that's for readonly and you need cloudformation:CreateStack. Add the following as a user policy.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1449904348000",
            "Effect": "Allow",
            "Action": [
                "cloudformation:CreateStack"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

It's entirely possible you'll need more permissions- for instance, to launch an EC2 instance, to (re)configure security groups, etc.

keparo
  • 33,450
  • 13
  • 60
  • 66
tedder42
  • 23,519
  • 13
  • 86
  • 102
38

What @tedder42 said, but I also had to add the following to my group policy before I could deploy to lambda from inside visual studio.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1449904348000",
            "Effect": "Allow",
            "Action": [
                "cloudformation:CreateStack",
                "cloudformation:CreateChangeSet",
                "cloudformation:ListStacks",
                "cloudformation:UpdateStack",
                "cloudformation:DescribeChangeSet",
                "cloudformation:ExecuteChangeSet"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
Chris Masterton
  • 2,197
  • 4
  • 24
  • 30
  • 5
    You'd need `cloudformation:DescribeStacks` as well if you plan on doing `servlerless info`. – pdeschen Nov 10 '17 at 21:14
  • 8
    This answer should be upvoted and +1 to @pdeschen saying you also need to add `cloudformation:DescribeStacks` if you're trying to deploy with serverless. I also had to add `cloudformation:DescribeStackResource`, `cloudformation:ValidateTemplate` – hummmingbear Feb 27 '18 at 23:31
  • I also added these 2 actions : cloudformation:DescribeStackEvents cloudformation:DeleteStack because I needed to permit, my users delete the stacks as well. – GhostCode Sep 24 '18 at 10:09
8

In my recent experience the policy required was

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1449904348000",
            "Effect": "Allow",
            "Action": [
                "cloudformation:CreateStack",
                "cloudformation:CreateChangeSet",
                "cloudformation:ListStacks",
                "cloudformation:UpdateStack",
                "cloudformation:DescribeStacks",
                "cloudformation:DescribeStackResource",
                "cloudformation:DescribeStackEvents",
                "cloudformation:ValidateTemplate",
                "cloudformation:DescribeChangeSet",
                "cloudformation:ExecuteChangeSet"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
mancvso
  • 306
  • 4
  • 4
6

I wasn't able to get the shorter versions shown above to work; what fixed things for me was extending @mancvso 's answer slightly to add "cloudformation:GetTemplateSummary":

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1449904348000",
            "Effect": "Allow",
            "Action": [
                "cloudformation:CreateStack",
                "cloudformation:CreateChangeSet",
                "cloudformation:ListStacks",
                "cloudformation:UpdateStack",
                "cloudformation:DescribeStacks",
                "cloudformation:DescribeStackResource",
                "cloudformation:DescribeStackEvents",
                "cloudformation:ValidateTemplate",
                "cloudformation:DescribeChangeSet",
                "cloudformation:ExecuteChangeSet",
                "cloudformation:GetTemplateSummary"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
TimD
  • 8,014
  • 2
  • 24
  • 34
4

if you have multiple AWS profiles, try to explicity

export AWS_ACCESS_KEY_ID=<value>
export AWS_SECRET_ACCESS_KEY=<value>

before trying

serverless deploy
Iridium Admin
  • 111
  • 1
  • 3
2

I fixed this issue by adding the permission to the user in the AWS console:

  1. Go to AWS Console
  2. Find the user whose credentials you are using IAM > Access Management > Users
  3. Permissions > 'Add Permissions' > 'Attach existing policies directly'
  4. Search for and select 'AWSCloudFormationFullAccess'
Alistair Colling
  • 1,363
  • 2
  • 19
  • 29
2

Just for others reference in case s/he was searching the issue and get here:

Make sure that you deleted the permissions boundary for that IAM user.

If you found that you have granted the cloudformation full access to the IAM user and still get the same error claiming User is not authorized to perform: cloudformation:CreateStack, then it's denied by the permissions boundary.

enter image description here

Jeff Tian
  • 5,210
  • 3
  • 51
  • 71
  • 1
    Thanks, goto https://console.aws.amazon.com/iam/home?region=us-west-1#/roles and enter AWSAmplifyExecutionRole-xxxxx, then click "Attach policies" button, and search "AWSCloudFormationFullAccess" and add this permison to the amplify role – diyism Mar 21 '21 at 09:31
1

These 2 helped me cross the line...

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "apigateway:*",
            "Resource": "*"
        }
    ]
}

and

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "cloudformation:ListStacks",
                "cloudformation:DescribeStackEvents",
                "cloudformation:CreateStack",
                "cloudformation:UpdateStack",
                "cloudformation:DescribeStackResource",
                "cloudformation:CreateChangeSet",
                "cloudformation:DescribeChangeSet",
                "cloudformation:ExecuteChangeSet",
                "cloudformation:ValidateTemplate"
            ],
            "Resource": "*"
        }
    ]
}
Sajjan Singh
  • 2,523
  • 2
  • 27
  • 34
Akber Iqbal
  • 14,487
  • 12
  • 48
  • 70
1

Create the following policy:

  1. Click on Policy -> Create Policy
  2. Under Select Service - Type EKS & Select 'EKS'
  3. Under Actions: Select 'All EKS Actions'
  4. Under Resources: Either select 'All resources' or Add ARN
  5. Click on Review Policy
  6. Type the name for the policy & create the policy.

Now, associate this policy to the user account. This should solve the issue & you should be able to create the stack.

Razikh
  • 173
  • 1
  • 6
0

With the recent updates in AWS, the following inline policy will also work.

{
   "Version": "2012-10-17",
   "Statement": [
       {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "cloudformation:DeleteStack"
            ],
            "Resource": "*"
        }
    ]
}
vseven
  • 1
  • 1
0

Here is an example policy that grants the necessary permissions to perform the cloudformation:CreateChangeSet action on the aws-ses-serverless-dev CloudFormation stack:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowCreateChangeSet",
            "Effect": "Allow",
            "Action": "cloudformation:CreateChangeSet",
            "Resource": "arn:aws:cloudformation:us-east-1:030198164798:stack/aws-ses-serverless-dev/*"
        }
    ]
}

You can add this policy to the ses-smtp-user.20230320-141906 IAM user by following these steps:

  1. Open the AWS Management Console and go to the IAM service.

  2. List In the left sidebar, click on "Users" and find the
    ses-smtp-user.20230320-141906 user.

  3. Click on the user to open its
    details page. Click on the "Permissions" tab.

  4. Click on the "Add
    inline policy" button to create a new policy.

  5. In the policy editor, select the "JSON" tab and paste the example policy shown above. Click on the "Review policy" button to review the policy.

  6. Give the policy a name and click on the "Create policy" button to create the policy and attach it to the user.

After adding the policy to the ses-smtp-user.20230320-141906 IAM user, try deploying your Serverless stack again and see if the issue will resolved.

Deva
  • 3
  • 5