[英]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.