skip to Main Content

Does anyone know how to activate with typescript CDK? There is literally no documentation from AWS how to set it up with their Lambda SDK.

any sample code?

2

Answers


  1. Here is the TypeScript sample:

    import * as lambda from "@aws-cdk/aws-lambda";
    import * as cdk from "@aws-cdk/core";
    
    export class LambdaSnapStartStack extends cdk.Stack {
        constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
            super(scope, id, props);
    
            const lambdaFunction = new lambda.Function(this, "lambda-function", {
                functionName: "MyPrettyFunction",
                runtime: lambda.Runtime.PYTHON_3_9,
                memorySize: 1024,
                timeout: cdk.Duration.seconds(30),
                handler: "my_lambda.lambda_handler",
                code: lambda.Code.fromAsset("my_lambda.zip")
                // other properties
            });
    
            // Enable SnapStart
            const cfnFunction = lambdaFunction.node.defaultChild as lambda.CfnFunction;
            cfnFunction.addPropertyOverride("SnapStart", { ApplyOn: "PublishedVersions" });
        }
    }
    
    Login or Signup to reply.
  2. I dont think so its possible with for any runtime other than java11 & java17

    AWS docs

    SnapStart supports the Java 11 and Java 17 (java11 and java17) managed runtimes. Other managed runtimes (such as nodejs18.x and python3.10), custom runtimes, and container images are not supported.

    If your lambda uses java runtime then you need to use snapstart property otherwise at this moment you cannot use snapstart feature for your lambda

    Ref: Docs

    AWS Cloud Development Kit (AWS CDK): Use the SnapStartProperty type.

    https://docs.aws.amazon.com/cdk/api/v2/java/software/amazon/awscdk/services/lambda/CfnFunction.SnapStartProperty.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search