Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let bucketName = 'coffeeshop-' + Math.random().toString(36).substring(7);
const coffeeShopBucket = new s3.Bucket(this, 'CoffeeShopBucket', {
bucketName: bucketName,
// The default removal policy is RETAIN, which means that cdk destroy will not attempt to delete
// the new bucket, and it will remain in your account until manually deleted. By setting the policy to
// DESTROY, cdk destroy will attempt to delete the bucket, but will error if the bucket is not empty.
//removalPolicy: cdk.RemovalPolicy.DESTROY, // NOT recommended for production code
});
coffeeShopBucket.grantPut(buildRole);
coffeeShopBucket.grantRead(buildRole);
coffeeShopBucket.grantReadWrite(buildRole);
coffeeShopBucket.grantWrite(buildRole);
new codebuild.Project(this, 'CodeBuildProject', {
role: buildRole,
source: defaultSource,
// Enable Docker AND custom caching
cache: codebuild.Cache.local(codebuild.LocalCacheMode.DOCKER_LAYER, codebuild.LocalCacheMode.CUSTOM),
environment: {
buildImage: codebuild.LinuxBuildImage.AMAZON_LINUX_2,
privileged: true,
},
buildSpec: codebuild.BuildSpec.fromObject({
version: '0.2',
phases: {
install:{
'runtime-versions': {
java: 'corretto8'
}
},
handler: 'pull_request.lambda_handler',
role: lambdaRole,
});
const codeBuildResultFunction = new Function(
this,
'CodeBuildResultFunction',
{
runtime: Runtime.PYTHON_3_7,
code: Code.asset(`${lambdaPath}/code-build-result`),
handler: 'code_build_result.lambda_handler',
role: lambdaRole,
},
);
const pullRequestProject = new Project(this, 'PullRequestProject', {
projectName: `${repository.repositoryName}-pull-request`,
source: Source.codeCommit({
repository,
}),
environment: {
buildImage,
computeType,
},
buildSpec,
});
pullRequestProject.onStateChange('PullRequestValidationRule', {
target: new LambdaFunction(codeBuildResultFunction),
});
const rule = repository.onPullRequestStateChange(
constructor(scope) {
super(scope, 'pipeline');
let project = new Project(this, 'deploy-site', {
description: 'Deploys website at scaleyourcloudformation.com',
timeout: Duration.minutes(30),
badge: true,
source: Source.gitHub({
cloneDepth: 1,
owner: 'jeshan',
repo: 'scale-your-cloudformation',
webhookFilters: [
FilterGroup.inEventOf([EventAction.PUSH]).andBranchIs(
'master',
),
],
}),
environment: { buildImage: LinuxBuildImage.STANDARD_2_0 },
buildSpec: BuildSpec.fromObject({
version: '0.2',