Skip to content

"Unable to assume specified IAM Role" after setting NextJS app up with CDK #2410

@mattias-sanfridsson

Description

@mattias-sanfridsson

Environment information

> npm error could not determine executable to run.

Node: V22.12.0
NPM: 10.9.0
CDK: 2.174.1 (build f353fc7)
Region: eu-north-1 (have also tried us-east-1 with same result)

Describe the bug

I've been able to use CDK to set up my stack and app in Amplify. This created an IAM Role. The Trust relationships of the role looks like this:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": [
                    "amplify.eu-north-1.amazonaws.com",
                    "amplify.amazonaws.com"
                ]
            },
            "Action": "sts:AssumeRole"
        }
    ]
}

The role has the following permission policies added for testing purposes:

  • AdministratorAccess
  • AdministratorAccess-Amplify

My CDK setup looks like this:

const amplifyApp = new amplify.App(this, 'MyAmplifyApp', {
  appName: 'my-nextjs-app',
  sourceCodeProvider: new amplify.GitHubSourceCodeProvider({
    owner: 'my-org',
    repository: 'nextjs-amplify-test',
    oauthToken: cdk.SecretValue.secretsManager('github-token', {jsonField: 'github-token'}),
  }),
  buildSpec: BuildSpec.fromObject({
    version: '1.0',
    frontend: {
      phases: {
        preBuild: {
          commands: ['npm ci'],
        },
        build: {
          commands: ['npm run build'],
        },
      },
      artifacts: {
        baseDirectory: '.next',
        files: ['**/*'],
      },
      cache: {
        paths: ['node_modules/**/*'],
      },
    },
  }),
});

// Add the main branch to the Amplify app
amplifyApp.addBranch('main');

When I push my code a deployment starts, but it fails on the provisioning step with the following error:

[ERROR]: !!! Unable to assume specified IAM Role. Please ensure the selected IAM Role has sufficient permissions and the Trust Relationship is configured correctly.
[INFO]: # Starting environment caching...
[INFO]: # Environment caching completed

Would be extremely thankful for any help. I've read through previous related issues but was unable to resolve this.

Reproduction steps

  1. Create a basic NextJS app
  2. Initiate CDK in the app with the TS stack provided above
  3. Run cdk synth, cdk bootstrap and cdk deploy
  4. Push a change to main
  5. The deployment should fail

Metadata

Metadata

Assignees

No one assigned

    Labels

    hostingIssue related to Amplify Hostingpending-community-responseIssue is pending a response from the author or communityquestionQuestion or confusion about some aspect of the product

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions