我想使用 AWS CodeBuild 从 Git 存储库运行 AWS CDK 合成 - 即,如果我更新存储库中的 CDK 应用程序代码,我希望 CloudFormation 堆栈自动更新。设置构建角色权限的最佳实践是什么?
问问题
2301 次
2 回答
3
对于 GitHub 存储库,您的 CodeBuild 角色不需要额外的权限,但它应该有权oauthToken
访问 GitHub。
对于 CodeCommit 存储库,创建import
一个codecommit.Repository
对象并使用一个CodeCommitSource
对象作为source
参数,构建角色权限将自动设置(特别是,将添加的权限将codecommit:GitPull
来自指定的存储库)。
见这里。
您可能还对 CDK 的应用交付包感兴趣。不过,它不只是创建一个 CodeBuild 项目,它使用 CodePipeline 来获取、构建和部署一个 CDK 应用程序,因此它可能比您想要的要多。
于 2019-01-03T12:15:20.683 回答
0
AWS 一个月前发布了一个新的 CDK 套件类,称为管道,其中包括几个实用程序,以简化设置自我修改管道的工作。此外,还有codepipeline-actions,其中包括将您的管道连接到 CodeCommit、GitHub、BitBucket 等的构造......
这是一个完整的示例(逐字来自链接的博客文章),使用 github 作为源,通过 CodePipeline 部署 lambda:
用你的堆栈创建一个阶段
import { CfnOutput, Construct, Stage, StageProps } from '@aws-cdk/core';
import { CdkpipelinesDemoStack } from './cdkpipelines-demo-stack';
/**
* Deployable unit of web service app
*/
export class CdkpipelinesDemoStage extends Stage {
public readonly urlOutput: CfnOutput;
constructor(scope: Construct, id: string, props?: StageProps) {
super(scope, id, props);
const service = new CdkpipelinesDemoStack(this, 'WebService');
// Expose CdkpipelinesDemoStack's output one level higher
this.urlOutput = service.urlOutput;
}
}
使用您的管道创建堆栈
import * as codepipeline from '@aws-cdk/aws-codepipeline';
import * as codepipeline_actions from '@aws-cdk/aws-codepipeline-actions';
import { Construct, SecretValue, Stack, StackProps } from '@aws-cdk/core';
import { CdkPipeline, SimpleSynthAction } from "@aws-cdk/pipelines";
/**
* The stack that defines the application pipeline
*/
export class CdkpipelinesDemoPipelineStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const sourceArtifact = new codepipeline.Artifact();
const cloudAssemblyArtifact = new codepipeline.Artifact();
const pipeline = new CdkPipeline(this, 'Pipeline', {
// The pipeline name
pipelineName: 'MyServicePipeline',
cloudAssemblyArtifact,
// Where the source can be found
sourceAction: new codepipeline_actions.GitHubSourceAction({
actionName: 'GitHub',
output: sourceArtifact,
oauthToken: SecretValue.secretsManager('github-token'),
owner: 'OWNER',
repo: 'REPO',
}),
// How it will be built and synthesized
synthAction: SimpleSynthAction.standardNpmSynth({
sourceArtifact,
cloudAssemblyArtifact,
// We need a build step to compile the TypeScript Lambda
buildCommand: 'npm run build'
}),
});
// This is where we add the application stages
// ...
}
}
于 2020-08-29T00:37:05.010 回答