英文:
How to enable assertions in AWS Lambda Java code?
问题
如何在AWS Lambda的Java代码中启用断言?
基本上,我希望AWS Lambda在Java代码中考虑我的断言语句。
英文:
How to enable assertions in AWS Lambda Java code ?
Basically I want AWS Lambda to take into account my assert statements in Java code.
答案1
得分: 2
如Bjorn所提到的,您需要启用-enableassertions
。
可以通过使用自定义运行时而不是默认的AWS来实现。这里有一个使用自定义运行时的示例 - https://github.com/andthearchitect/aws-lambda-java-runtime
注意:还有一个选项JAVA_TOOL_OPTIONS
,在尝试检查自定义运行时之前,请尝试使用它。
另一个选项可以是将断言替换为类似以下的内容:
if (!condition) {
throw new AssertionError();
}
如果是您自己的代码,第二个选项听起来更好。
英文:
As mentioned by Bjorn you have too enable -enableassertions
.
It is possible to have them but with using custom runtime not the default AWS.
Here is one example of having custom runtime - https://github.com/andthearchitect/aws-lambda-java-runtime
Note: There is an option JAVA_TOOL_OPTIONS, please give it a try before checking custom runtime.
Another option could be just replace asserting with something like .
if (!condition) {
throw new AssertionError();
}
If it is your own code second options sounds better.
答案2
得分: 1
启用断言需要使用-enableassertions
启动命令。不幸的是,在AWS Lambda中无法向JVM传递参数,只支持环境变量。回答你的问题:不,这是不可能的。
英文:
To enable assertions assertions you need to use the -enableassertions
startup command. Unfortunately you cannot give arguments to the JVM with AWS Lambda. Only environment variables are supported. To answer your question: no this is not possible.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论