Skip to content

Commit

Permalink
feat(pipelines): Allow adding PolicyStatements to CodeBuild Project role
Browse files Browse the repository at this point in the history
Fixes aws#9163
  • Loading branch information
luisantonioa committed Aug 7, 2020
1 parent c095da2 commit 9af4e17
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions packages/@aws-cdk/pipelines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,41 @@ const validationAction = new ShellScriptAction({
});
```
#### Add Additional permissions to the CodeBuild Project Role for building and synthing
You can customize the role permissions used by the CodeBuild project so it has access to
the needed resources. eg: Adding CodeArtifact repo permissions so we pull npm packages
from the CA repo instead of NPM.
```ts
class MyPipelineStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
...
const pipeline = new CdkPipeline(this, 'Pipeline', {
...
synthAction: SimpleSynthAction.standardNpmSynth({
sourceArtifact,
cloudAssemblyArtifact,

// Use this to customize and a permissions required for the build
// and synth
rolePolicyStatements: [
new PolicyStatement({
actions: ['codeartifact:*', 'sts:GetServiceBearerToken'],
resources: ['arn:codeartifact:repo:arn'],
}),
],

// Then you can login to codeartifact repository
// and npm will now pull packages from your repository
// Note the codeartifact login command requires more params to work.
buildCommand: 'aws codeartifact login --tool npm && npm run build',
}),
});
}
}
```
## CDK Environment Bootstrapping
An *environment* is an *(account, region)* pair where you want to deploy a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export class SimpleSynthAction implements codepipeline.IAction {
},
});

if (this.props.rolePolicyStatements != undefined) {
if (this.props.rolePolicyStatements !== undefined) {
this.props.rolePolicyStatements.forEach(policyStatement => {
project.addToRolePolicy(policyStatement);
});
Expand Down

0 comments on commit 9af4e17

Please sign in to comment.