Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mattias-persson opened this issue Jan 7, 2025 · 1 comment
Labels
hosting Issue related to Amplify Hosting pending-community-response Issue is pending a response from the author or community question Question or confusion about some aspect of the product

Comments

@mattias-persson
Copy link

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
@mattias-persson mattias-persson added the pending-triage Incoming issues that need categorization label Jan 7, 2025
@ykethan ykethan added the hosting Issue related to Amplify Hosting label Jan 7, 2025
@Jay2113
Copy link

Jay2113 commented Jan 13, 2025

Hi @mattias-persson 👋 , thanks for reaching out to us. To deploy Amplify Gen 2 apps with branch-based deployments, you will need to use the AmplifyBackendDeployFullAccess managed policy to deploy backend resources during a fullstack deployment. The service role should also have the following trust relationship policy:

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

Documentation: https://docs.amplify.aws/react/reference/iam-policy/

@Jay2113 Jay2113 added question Question or confusion about some aspect of the product pending-community-response Issue is pending a response from the author or community and removed pending-triage Incoming issues that need categorization labels Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hosting Issue related to Amplify Hosting pending-community-response Issue is pending a response from the author or community question Question or confusion about some aspect of the product
Projects
None yet
Development

No branches or pull requests

3 participants