Skip to content

Error when using AWS Lambda Profiler Extension #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Vadym79 opened this issue Mar 18, 2025 · 4 comments
Closed

Error when using AWS Lambda Profiler Extension #529

Vadym79 opened this issue Mar 18, 2025 · 4 comments

Comments

@Vadym79
Copy link

Vadym79 commented Mar 18, 2025

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

@maxday maxday pinned this issue Mar 18, 2025
@maxday maxday unpinned this issue Mar 18, 2025
@maxday
Copy link
Contributor

maxday commented Mar 18, 2025

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

@Vadym79
Copy link
Author

Vadym79 commented Mar 18, 2025

@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.

@maxday
Copy link
Contributor

maxday commented Mar 18, 2025

@Vadym79 thanks a lot for your investigation, that makes total sense.
I will create a new PR to document this and will also bump the s3 sdk version.

@maxday
Copy link
Contributor

maxday commented Mar 19, 2025

Closing as #530 has been merged
Thanks again for the feedback 💯

@maxday maxday closed this as completed Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants