Error when using AWS Lambda Profiler Extension
Closed this issue · 4 comments
I just build the AWS Lambda Profiler Extension as descibed in here, published it as a Lambda layer and used it in my sample application.
During the Lambda invocation I first saw the log message
[PROFILER] premain is starting
and then got the following error message:
Class software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute does not have member field 'software.amazon.awssdk.core.interceptor.ExecutionAttribute BUSINESS_METRICS': java.lang.NoSuchFieldError
java.lang.NoSuchFieldError: Class software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute does not have member field 'software.amazon.awssdk.core.interceptor.ExecutionAttribute BUSINESS_METRICS'
software.amazon.awssdk.services.dynamodb.endpoints.internal.DynamoDbResolveEndpointInterceptor.resolveAndRecordAccountIdFromIdentity(DynamoDbResolveEndpointInterceptor.java:586)
at software.amazon.awssdk.services.dynamodb.endpoints.internal.DynamoDbResolveEndpointInterceptor.ruleParams(DynamoDbResolveEndpointInterceptor.java:167)
at software.amazon.awssdk.services.dynamodb.endpoints.internal.DynamoDbResolveEndpointInterceptor.modifyRequest(DynamoDbResolveEndpointInterceptor.java:116)
at software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain.modifyRequest(ExecutionInterceptorChain.java:65)
at software.amazon.awssdk.awscore.internal.AwsExecutionContextBuilder.runInitialInterceptors(AwsExecutionContextBuilder.java:243)
at software.amazon.awssdk.awscore.internal.AwsExecutionContextBuilder.invokeInterceptorsAndCreateExecutionContext(AwsExecutionContextBuilder.java:132)
at software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler.invokeInterceptorsAndCreateExecutionContext(AwsSyncClientHandler.java:67)
at software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.lambda$execute$1(BaseSyncClientHandler.java:76)
at software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.measureApiCallSuccess(BaseSyncClientHandler.java:182)
at software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.execute(BaseSyncClientHandler.java:74)
at software.amazon.awssdk.core.client.handler.SdkSyncClientHandler.execute(SdkSyncClientHandler.java:45)
at software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler.execute(AwsSyncClientHandler.java:53)
at software.amazon.awssdk.services.dynamodb.DefaultDynamoDbClient.putItem(DefaultDynamoDbClient.java:4435)
at software.amazonaws.example.product.dao.DynamoProductDao.putProduct(DynamoProductDao.java:56)
at software.amazonaws.example.product.handler.CreateProductHandler.handleRequest(CreateProductHandler.java:27)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
You can test my using my application : build it with mvn clean package and deploy it with sam deploy. Then use AWSLambdaWithProfilerLayerJava21API in API Gateway and invoke /product PUT HTTP method with the body { "id": 1, "name": "Print 10x13", "price": 0.15 }. This application is simple: API Gateway invokes Lambda Function (PutProductWithPureJava21WithProfilerLayer) and it persists the product record into the DynamoDB table AWSLambdaWithProfilerLayerJava21ProductsTable.
If I comment the following line in the template.yaml
#JAVA_TOOL_OPTIONS: -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -javaagent:/opt/profiler-extension.jar
which defines the agent, everything works fine. Please advice
Thanks for reaching out @Vadym79 and for the reproducer
I will try to reproduce the issue on my end to root cause the issue.
Thanks
@maxday I understood why it happened: the error occured in the sdk-core.jar. In build.gradle you use software.amazon.awssdk:s3:2.28.9 which then also needs sdk-core.jar. In the pom.xml of my applciation I used the higher version (2.31.1) of the bom of software.amazon.awssdk, so there are 2 different versions of sdk-core.jar in the classpath : one via Lambda layer for s3 communication and one via my application itself (dynamodb client which I use requires it). The one from the layer has priority and boom, there is a mismatch as dynamodb client requires things (like software.amazon.awssdk.core.interceptor.ExecutionAttribute BUSINESS_METRICS member field) in the sdk-core.jar which are not there in the older version.
Please improve your documentation, that the usage of the different versions of all dependencies (especially of s3, but also aws-lambda-java-core and aws-lambda-java-events) for building the lambda profiler extension and in the application itself could potentially lead to such an effect.
After I have fixed in in my local copy of the lambda profiler and rebuilt and redeployed the lambda layer with the profile extension I at least don't see any thrown errors.