aws cdk deploy lambda function to mutiple region

0

Currently, I have my code pipeline set up, and it just deploy the stack and the lambda function to the region(ap-north-east) in which I have set up in the aws config in AWS CLI. How can I create another action that in the same deploy stage which can deploy the lambda function to ap-south-east. I can reproduce this in AWS console, but not sure how to make it in CDK

Here is my pipeline code

This is my pipeline stack

import * as cdk from 'aws-cdk-lib'
import { Construct } from 'constructs'
import * as codecommit from 'aws-cdk-lib/aws-codecommit'
import { DbcallPipelienStage } from './pipeline-stage'
import { CodeBuildStep, CodePipeline, CodePipelineSource } from 'aws-cdk-lib/pipelines'


export class DbCallPipelineStack extends cdk.Stack {
    constructor(scope: Construct, id: string, props?: cdk.StackProps) {
        super(scope, id, props)

        // Creates a CodeCommit repository called 'dbcallRepo'

        const repo = new codecommit.Repository(this, 'dbcallRepo', {
            repositoryName: 'dbcallRepo'
        })

        // The basic pipeline declaration. This sets the initial structure
        // of our pipeline

        const pipeline = new CodePipeline(this, 'Pipeline', {
            pipelineName: 'WorkshopPipeline',
            synth: new CodeBuildStep('SynthStep', {
                input: CodePipelineSource.codeCommit(repo, 'main'),

                installCommands: [
                    'npm isntall -g aws-cdk'
                ],
                commands: [
                    'npm ci',
                    'npm run build',
                    'npx cdk synth'
                ]
            })
        })
 // Below is creating the deploy stage and add an action
        const deploy = new DbcallPipelienStage(this, 'Deploy');
        const deployStage = pipeline.addStage(deploy)
    }
}

This is my pipeline stage which is try to instantiate my lambda stack

import { Stage, StageProps } from 'aws-cdk-lib'
import { CdkTestStack } from './cdk-test-stack'
import { Construct } from 'constructs'



export class DbcallPipelienStage extends Stage {
    constructor(scope: Construct, id: string, props?: StageProps) {
        super(scope, id, props);


        new CdkTestStack(this, 'dbcall')

    }
}



1 Antwort
0

You need to provide the region to the stack via StackProps and, if relevant, ensure your deployment role has permission to deploy to the region. Refer to the documentation here: interface StackProps

import { Stage, StageProps } from 'aws-cdk-lib'
import { CdkTestStack } from './cdk-test-stack'
import { Construct } from 'constructs'

export class DbcallPipelienStage extends Stage {
    constructor(scope: Construct, id: string, props?: StageProps) {
        super(scope, id, props);
        new CdkTestStack(this, 'dbcall-ap-north-east)',{ env:{region:'ap-north-east'} })
        new CdkTestStack(this, 'dbcall-ap-south-east)',{ env:{region:'ap-south-east'} })
    }
}
profile picture
beantwortet vor 7 Monaten
  • Thanks for giving the guide, I tried to specify the env with the region Now I received the error dur the build stage in the pipeline

    Error: Pipeline stack which uses cross-environment actions must have an explicitly set region

    [Container] 2023/10/19 03:36:21 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: npx cdk synth. Reason: exit status 1

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen