简体   繁体   English

如何使用 SnapStart 将 CRaC 运行时挂钩附加到 AWS Lambda?

[英]How do you attach CRaC runtime hooks to an AWS Lambda with SnapStart?

I tried to follow the instructions from the online docs exactly, and I even included the System.identityHashCode(this) on each line to make sure it was the same object and wasn't being garbage collected:我试图完全按照在线文档中的说明进行操作,我什至在每一行都包含了System.identityHashCode(this)以确保它是同一个对象并且没有被垃圾收集:

public class MyLambdaHandler extends AppConfigHelper implements RequestStreamHandler, Resource {
    public MyLambdaHandler() {
        System.out.println("Constructor called: " + System.identityHashCode(this));
        Core.getGlobalContext().register(this);
    }
    @Override
    public void beforeCheckpoint(org.crac.Context<? extends Resource> context) throws Exception {
        System.out.println("Before checkpoint: " + System.identityHashCode(this));
    }
    @Override
    public void afterRestore(org.crac.Context<? extends Resource> context) throws Exception {
        System.out.println("After restore: " + System.identityHashCode(this));
    }
    @Override
    public void handleRequest(final InputStream input, final OutputStream output, final Context context) throws IOException {
        System.out.println("Request handler called: " + System.identityHashCode(this));
    }
}

But on the first invocation, you can see that neither the beforeCheckpoint() or afterRestore() are getting called:但是在第一次调用时,您可以看到beforeCheckpoint()afterRestore()都没有被调用:

Constructor called: 91912419
START RequestId: b56b282f-4712-4d18-b300-f6e031c9468a Version: $LATEST
Request handler called: 91912419
END RequestId: b56b282f-4712-4d18-b300-f6e031c9468a
REPORT RequestId: b56b282f-4712-4d18-b300-f6e031c9468a  Duration: 173.24 ms Billed Duration: 174 ms Memory Size: 1024 MB    Max Memory Used: 196 MB Init Duration: 2084.86 ms   

On the second invocation, you can see the same object 91912419 is being reused, but again neither of the runtime hooks are being called:在第二次调用时,您可以看到相同的对象91912419被重用,但同样没有调用运行时挂钩:

START RequestId: b1ca407e-725c-4c17-93aa-46251f1c65a6 Version: $LATEST
Request handler called: 91912419
END RequestId: b1ca407e-725c-4c17-93aa-46251f1c65a6
REPORT RequestId: b1ca407e-725c-4c17-93aa-46251f1c65a6  Duration: 1.58 ms   Billed Duration: 2 ms   Memory Size: 1024 MB    Max Memory Used: 195 MB 

You need to manually publish a version for SnapStart to work, you can't use SnapStart on $LATEST .您需要手动发布 SnapStart 的版本才能工作,您不能在$LATEST上使用 SnapStart。 From the docs ( https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html#snapstart-runtimes ):从文档( https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html#snapstart-runtimes ):

You can use SnapStart only on published function versions and aliases that point to versions.您只能在已发布的函数版本和指向版本的别名上使用 SnapStart。 You can't use SnapStart on a function's unpublished version ($LATEST).您不能在函数的未发布版本 ($LATEST) 上使用 SnapStart。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用无服务器框架的 Lambda Snapstart - Lambda Snapstart with Serverless framework 如何使用 `experimental-edge` runtime 在 AWS lambda 中运行 nextjs - How to run nextjs in AWS lambda with `experimental-edge` runtime 如何使用 terraform 为 aws lambda 指定 dotnet 6 运行时? - How to specify the dotnet 6 runtime for aws lambda, using terraform? 您如何使用别名将您的 AWS lambda 从一个 envr 转移/升级到另一个(例如,dev 到 prod)? - How do you shift/escalate your AWS lambda from one envr to another (eg. dev to prod) using alias? 您如何为 CDK 中的 aws lambda 覆盖 docker 的“cmd”? - How can you override "cmd" of docker for aws lambda in CDK? 如何在 AWS Lambda 上运行我的 telegraf 机器人 - how do I run my telegraf bot on AWS Lambda 如何使用 AWS CDK 中的 InvokeLambda 将 JSON 传递给 AWS StepFunction 中的 lambda - How do I pass JSON to lambda in AWS StepFunction using InvokeLambda in AWS CDK 如何使用 Lambda 批量加载 AWS Neptune? - How do i Bulk Load AWS Neptune using a Lambda? 如何使用 lerna 将 monorepo 代码部署到 AWS Lambda? - How do I deploy monorepo code to AWS Lambda using lerna? 如何在 AWS Pinpoint 中创建自定义控制面板? - How do you create custom dashboards in AWS Pinpoint?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM