aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.35k stars 3.77k forks source link

(aws-amplify-alpha): Amplify ProductionBranch not being populated on cdk deploy #18863

Open crs-k opened 2 years ago

crs-k commented 2 years ago

What is the problem?

When using CDK to deploy Amplify, the Production Branch field is not being populated. Production Branch also does not populate after successful build. I cannot find anywhere in the documentation where ProductionBranch can be defined. This is the closest documentation i could find: Amplify API.

I also tried with the aws_amplify package for cdk2.0 as well.

image

Reproduction Steps

Deploy Amplify App using GitHub repo as the provider.

Code I am using:

import * as cdk from "aws-cdk-lib";
import * as amplify from '@aws-cdk/aws-amplify-alpha';
import { Construct } from "constructs";

export interface CdkInfraStack extends cdk.StackProps {
  owner: string;
  repository: string;
  role: string;
  domain: string;
}

export class AmplifyInfraStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props: CdkInfraStack) {
    super(scope, id, props);

    // Amplify Application
    const amplifyApp = new amplify.App(this, "next-js-amplify", {

      sourceCodeProvider: new amplify.GitHubSourceCodeProvider({
        owner: props.owner,
        repository: props.repository,
        oauthToken: cdk.SecretValue.secretsManager("github/pat/crs-k", {
          jsonField: "githubPat",
        }),

      }),
      role: cdk.aws_iam.Role.fromRoleArn(this,'service-role',props.role) // necessary for explictly defining a service role that can create other resources as needed.
    });

    const main =  amplifyApp.addBranch("main", {autoBuild: true}); 

    const domain = amplifyApp.addDomain(props.domain, {
      enableAutoSubdomain: true, // subdomains auto registered for branches
      autoSubdomainCreationPatterns: ['*'], // regex for branches that should auto registered as subdomains
    });
    domain.mapRoot(main); // map main branch to domain root
    domain.mapSubDomain(main, 'www'); 
  } 

}

What did you expect to happen?

Production Branch field to be populated with addBranch or default branch name.

What actually happened?

Production Branch field was unpopulated.

CDK CLI Version

2.10.0

Framework Version

No response

Node.js Version

17.3

OS

windows & ubuntu

Language

Typescript

Language Version

4.5.5

Other information

No response

cyuste commented 1 year ago

This code solves the issue

const main = mySpaApp.addBranch('main', {
      stage: 'PRODUCTION',
    });