1 year ago

#375757

test-img

lsichip

AWS CodePipeline and CodeCommit in different regions (or AWS accounts) using CDK

Basically, I want to build the pipeline that exists in one AWS acc, uses CodeCommit from another AWS acc, and deploys something in a third acc. I have this code for deploying my pipeline:

import * as codecommit from '@aws-cdk/aws-codecommit';
import * as codepipeline from '@aws-cdk/aws-codepipeline';
import * as codepipeline_actions from '@aws-cdk/aws-codepipeline-actions';

const repoArn = `arn:aws:codecommit:${vars.sourceRegion}:${vars.sourceAccount}:${vars.sourceRepo}`
const repo = codecommit.Repository.fromRepositoryArn(this, 'Source-repo', repoArn);

const sourceArtifact = new codepipeline.Artifact();

let trigger = CodeCommitTrigger.EVENTS

const sourceAction = new codepipeline_actions.CodeCommitSourceAction({
    branch: vars.sourceBranch,
    actionName: 'Source',
    trigger: trigger,
    output: sourceArtifact,
    repository: repo,
    variablesNamespace: 'SourceVariables',
    codeBuildCloneOutput: true,
});

const pipelineBucket = s3.Bucket.fromBucketArn(this, 'pipelineBucket', BucketArn);

const pipeline = new codepipeline.Pipeline(this, 'CodePipeline', {
    artifactBucket: pipelineBucket,
    crossAccountKeys: true,
    role: roles.codePiplineRole,
    pipelineName: name,
    stages: [
        {
            stageName: 'Source',
            actions: [sourceAction],             
        },
    ],
});

If I run this I'll get the error: Source action 'Source' must be in the same region as the pipeline But they are both in the same region, and even in the same acc.

If I change codecommit.Repository.fromRepositoryArn to codecommit.Repository.fromRepositoryName then there will be no errors.

Is there any way to import an existing repo from ARN?

amazon-web-services

aws-cdk

aws-codepipeline

aws-codecommit

0 Answers

Your Answer

Accepted video resources