在 AWS CDK 中,应该如何将 CodeStarConnectionsSourceAction 用作 CodePipeline 的输入?
In AWS CDK, how should CodeStarConnectionsSourceAction be used as input to a CodePipeline?
我正在尝试建立一个从 Github 获取代码并部署它的管道(Lambda、DynamoDB 等,使用 CDK)。我现在正试图让它与 CodeStarConnectionsSourceAction
一起工作,但我的代码因以下错误而失败:
[Example4BePipeline/Example4BePipeline/Pipeline] Action Synth in stage Build: first stage may only contain Source actions
[Example4BePipeline/Example4BePipeline/Pipeline] Action 'Synth' is using input Artifact 'Sources', which is not being produced in this pipeline
我产生该错误的代码是:
import * as cdk from "aws-cdk-lib"
import {Construct} from "constructs"
import {Example4BeDeployStage} from "./example4-be-deploy-stage"
import {CodeBuildStep, CodePipeline, CodePipelineFileSet} from "aws-cdk-lib/pipelines"
import {CodeStarConnectionsSourceAction} from "aws-cdk-lib/aws-codepipeline-actions";
import {Artifact} from "aws-cdk-lib/aws-codepipeline";
export class PipelineStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props)
const sourceOutput = new Artifact("Sources");
const sourceAction = new CodeStarConnectionsSourceAction({
actionName: "Github",
owner: "username",
repo: "example4-be",
output: sourceOutput,
connectionArn: "arn:aws:codestar-connections:us-east-1:....:connection/...."
})
const pipeline = new CodePipeline(this, "Example4BePipeline", {
pipelineName: "Example4BePipeline",
synth: new CodeBuildStep("Synth", {
input: CodePipelineFileSet.fromArtifact(sourceOutput),
installCommands: [
"npm install -g aws-cdk"
],
commands: [
"npm ci",
"npm run build",
"npx cdk synth"
]
}
),
selfMutation: false // TODO: remove before committing.
})
}
}
我做错了什么?
我弄明白了,这是工作代码,很多shorter/concise:
import * as cdk from "aws-cdk-lib"
import {Construct} from "constructs"
import {Example4BeDeployStage} from "./example4-be-deploy-stage"
import {CodeBuildStep, CodePipeline, CodePipelineSource} from "aws-cdk-lib/pipelines"
export class PipelineStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props)
const pipeline = new CodePipeline(this, "Example4BePipeline", {
pipelineName: "Example4BePipeline",
synth: new CodeBuildStep("Synth", {
input: CodePipelineSource.connection("username/example4-be", "main", {
connectionArn: "arn:aws:codestar-connections:us-east-1:....:connection/....",
}),
installCommands: [
"npm install -g aws-cdk"
],
commands: [
"npm ci",
"npm run build",
"npx cdk synth"
]
}
),
selfMutation: false // TODO: remove before committing.
})
}
}
我正在尝试建立一个从 Github 获取代码并部署它的管道(Lambda、DynamoDB 等,使用 CDK)。我现在正试图让它与 CodeStarConnectionsSourceAction
一起工作,但我的代码因以下错误而失败:
[Example4BePipeline/Example4BePipeline/Pipeline] Action Synth in stage Build: first stage may only contain Source actions
[Example4BePipeline/Example4BePipeline/Pipeline] Action 'Synth' is using input Artifact 'Sources', which is not being produced in this pipeline
我产生该错误的代码是:
import * as cdk from "aws-cdk-lib"
import {Construct} from "constructs"
import {Example4BeDeployStage} from "./example4-be-deploy-stage"
import {CodeBuildStep, CodePipeline, CodePipelineFileSet} from "aws-cdk-lib/pipelines"
import {CodeStarConnectionsSourceAction} from "aws-cdk-lib/aws-codepipeline-actions";
import {Artifact} from "aws-cdk-lib/aws-codepipeline";
export class PipelineStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props)
const sourceOutput = new Artifact("Sources");
const sourceAction = new CodeStarConnectionsSourceAction({
actionName: "Github",
owner: "username",
repo: "example4-be",
output: sourceOutput,
connectionArn: "arn:aws:codestar-connections:us-east-1:....:connection/...."
})
const pipeline = new CodePipeline(this, "Example4BePipeline", {
pipelineName: "Example4BePipeline",
synth: new CodeBuildStep("Synth", {
input: CodePipelineFileSet.fromArtifact(sourceOutput),
installCommands: [
"npm install -g aws-cdk"
],
commands: [
"npm ci",
"npm run build",
"npx cdk synth"
]
}
),
selfMutation: false // TODO: remove before committing.
})
}
}
我做错了什么?
我弄明白了,这是工作代码,很多shorter/concise:
import * as cdk from "aws-cdk-lib"
import {Construct} from "constructs"
import {Example4BeDeployStage} from "./example4-be-deploy-stage"
import {CodeBuildStep, CodePipeline, CodePipelineSource} from "aws-cdk-lib/pipelines"
export class PipelineStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props)
const pipeline = new CodePipeline(this, "Example4BePipeline", {
pipelineName: "Example4BePipeline",
synth: new CodeBuildStep("Synth", {
input: CodePipelineSource.connection("username/example4-be", "main", {
connectionArn: "arn:aws:codestar-connections:us-east-1:....:connection/....",
}),
installCommands: [
"npm install -g aws-cdk"
],
commands: [
"npm ci",
"npm run build",
"npx cdk synth"
]
}
),
selfMutation: false // TODO: remove before committing.
})
}
}