2

I am trying to create an AWS Code Pipeline to create a DynamoDB table in one of the stages. I was able to successfully deploy the same code with CDK v1. now trying to replicate the same on CDK v2. I am getting an error Pipeline stack which uses cross-environment actions must have an explicitly set region

Here's the complete code:

    import { Stack, StackProps, Stage, StageProps } from "aws-cdk-lib";
    import { AttributeType, Table } from "aws-cdk-lib/aws-dynamodb";
    import {
      CodePipeline,
      CodePipelineSource,
      ShellStep,
    } from "aws-cdk-lib/pipelines";
    import { Construct } from "constructs";
    
    export class DdbStack extends Stack {
      constructor(scope: Construct, id: string, props?: StackProps) {
        super(scope, id, props);
    
        new Table(this, "TestTable", {
          partitionKey: { name: "id", type: AttributeType.STRING },
        });
      }
    }
    
    class MyApplication extends Stage {
      constructor(scope: Construct, id: string, props?: StageProps) {
        super(scope, id, props);
        new DdbStack(this, `${id}-ddb`, {});
      }
    }
    
    export class PipelineStack extends Stack {
      constructor(scope: Construct, id: string, props?: StackProps) {
        super(scope, id, props);
        const pipeline = new CodePipeline(this, `${id}-PipelineStack-`, {
          crossAccountKeys: true,
          selfMutation: false,
          pipelineName: "MangokulfiCDK",
          synth: new ShellStep("Synth", {
            input: CodePipelineSource.connection("gowtham91m/mango-cdk", "main", {
              connectionArn:
                "arn:aws:codestar-connections:us-west-2:147866640792:connection/4b18bea2-9eb6-47b1-bbdc-adb3bf6fd2a9",
            }),
            commands: ["npm ci", "npm run build", "npx cdk synth"],
          }),
        });
    
        pipeline.addStage(
          new MyApplication(this, `Staging`, {
            env: {
              account: "123456789123",
              region: "us-west-2",
            },
          })
        );
        pipeline.buildPipeline();
      }
    }
fedonev
  • 20,327
  • 2
  • 25
  • 34
Gowtham M
  • 349
  • 3
  • 18
  • 2
    Are you passing an explicit [environment](https://docs.aws.amazon.com/cdk/v2/guide/environments.html) for `PipelineStack` when you construct it in your `app.ts`? – fedonev Jan 27 '23 at 08:25
  • I wasn't passing an env. that was the problem. fixed now. – Gowtham M Jan 27 '23 at 15:50

0 Answers0