Solution to deploy lambdas in product provisioned using Service Catalog. Please see stacks configuration related
Configuring the service
Add to parent CF Stack
propagated-lambdas.ts
import * as cdk from '@aws-cdk/core';
import * as s3 from '@aws-cdk/aws-s3';
import * as s3Deployment from '@aws-cdk/aws-s3-deployment';
import {join} from 'path';
export class LyrisHqPropagatedLamdasDeployment extends cdk.Construct {
public readonly propagatedLambdasBucket: s3.Bucket;
constructor(public stack: cdk.Construct, id: string) {
super(stack, id);
this.propagatedLambdasBucket = new s3.Bucket(this, 'PropagatedBucket',{
removalPolicy: cdk.RemovalPolicy.DESTROY,
});
const lambdaZipFilesDirPath = join(__dirname, 'path', 'to', 'lambda', 'zips');
new s3Deployment.BucketDeployment(this,
`PropagatedLambdasDeployment`,
{
destinationBucket: this.propagatedLambdasBucket,
sources: [s3Deployment.Source.asset(lambdaZipFilesDirPath)]
});
}
}
Please note that aws-s3-deployment is experimental feature, it's implemented as custom resource with lambda inside, so you will probably see some unexpected resources in your diff.
Add CfnParameter to your child stack
...
const zipLambdasBucketName = new cdk.CfnParameter(this, 'LambdaS3Bucket').valueAsString;
...
And use it later to create lambdas
const bucket = s3.Bucket.fromBucketAttributes( this, 'ImportedLambdaBucket',
{
bucketArn: `arn:aws:s3:::${zipLambdasBucketName}`,
}
);
const defaultProps = {
code: lambda.Code.fromBucket(this.bucket, `${lambdaName}.zip`);
handler: 'index.handler',
role: customRole,
runtime: lambda.Runtime.NODEJS_12_X,
retryAttempts: 0,
timeout: cdk.Duration.seconds(30),
};
new lambda.Function(scope, id, defaultProps);
Also you should provide the parameter during product launch. See link
Comments
0 comments
Please sign in to leave a comment.