Skip to content

Instantly share code, notes, and snippets.

@kimisme9386
Created April 27, 2021 09:19
Show Gist options
  • Save kimisme9386/cf5a35a17f9399fa3c2c7f4471e6086b to your computer and use it in GitHub Desktop.
Save kimisme9386/cf5a35a17f9399fa3c2c7f4471e6086b to your computer and use it in GitHub Desktop.
CDK Get Secret Manager
import * as cdk from '@aws-cdk/core';
/**
* Using other type of secrets of AWS Secrets Manager
*/
const gitHubToken = cdk.SecretValue.secretsManager('arn:aws:secretsmanager:ap-northeast-1:your account id:secret:cusotm-name-YWWmII', {
jsonField: 'your key name',
})
/**
* Put it into lambda environment
*/
const lambdaFunc = new lambda.Function(this, 'CodepipelineEventLambda', {
code: lambda.Code.fromAsset(
path.join(__dirname, '../lambda/codepipeline-event'),
{
bundling: {
user: 'root',
image: lambda.Runtime.NODEJS_14_X.bundlingImage,
command: [
'bash',
'-c',
[
'npm install',
'npm run build',
'cp -r /asset-input/dist /asset-output/',
'npm install --only=production',
'cp -a /asset-input/node_modules /asset-output/',
].join(' && '),
],
},
}
),
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'dist/codepipelineEventLambda.handler',
environment: {
GITHUB_PERSONAL_TOKEN: gitHubToken ? `${gitHubToken}` : '',
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment