Skip to content

Conversation

@msailes
Copy link
Contributor

@msailes msailes commented Jul 8, 2021

Issue #, if available:

Description of changes:
GraalVM config and regression test.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@msailes msailes self-assigned this Jul 12, 2021
@msailes msailes changed the title Graalvm support GraalVM support Jul 12, 2021
@szab100
Copy link

szab100 commented Sep 16, 2021

Hi @msailes, what is this PR waiting for? We are facing with the same issues when trying to use spring native with graalvm..

@msailes
Copy link
Contributor Author

msailes commented Sep 16, 2021

@szab100 if possible could you contact me at msailes@amazon.co.uk

Thanks,

@msailes
Copy link
Contributor Author

msailes commented Sep 22, 2021

@szab100 could you 👍 this issue please. #272

@stejsj
Copy link

stejsj commented Apr 5, 2022

@msailes should the runtime client work with graalvm? We use scala and are trying to use your approach to get a native-image running to reduce cold start and resource requirements.

Sadly I get this error
START RequestId: 3a579869-9b96-46d7-9ce4-8c049a79d6c1 Version: $LATEST
[appconfig agent] 2022/04/05 10:36:21 INFO AppConfig Lambda Extension 2.0.45
[appconfig agent] 2022/04/05 10:36:21 INFO serving on localhost:2772
starting outage runtime...
Failed to load the native runtime interface client library aws-lambda-runtime-interface-client.glibc.so. Exception: null
Failed to load the native runtime interface client library aws-lambda-runtime-interface-client.musl.so. Exception: null
EXTENSION Name: AppConfigAgent State: Ready Events: [SHUTDOWN,INVOKE]
END RequestId: 3a579869-9b96-46d7-9ce4-8c049a79d6c1
REPORT RequestId: 3a579869-9b96-46d7-9ce4-8c049a79d6c1 Duration: 253.23 ms Billed Duration: 254 ms Memory Size: 2048 MB Max Memory Used: 56 MB
XRAY TraceId: 1-624c1ba4-441854bd0da7b1425ca04379 SegmentId: 14184b9f35ddfe28 Sampled: true

Eventhough I tried to manually include those two libraries as native-image resource args
example -H:IncludeResources="+baseDirectory.value / "src" / "main" / "resources" / "META-INF" / "resources" / "aws-lambda-runtime-interface-client.glibc.so"

We have been struggling quite a lot getting this to work, any thoughts, hints or ideas?

Thanx in advance
Steffen

@msailes
Copy link
Contributor Author

msailes commented Apr 5, 2022

Hi @stejsj ,

It is not currently supported no. The best thing to do would be to copy the config files from this sample application.

https://github.com/aws-samples/serverless-graalvm-demo/tree/main/software/products/src/main/resources/META-INF/native-image

@stejsj
Copy link

stejsj commented Apr 5, 2022

Thanks @msailes I actually allready did that, but native-image fails when i provide the config param -H:ReflectionConfigurationResources="+ baseDirectory.value / "src" / "main" / "resources" / "META-INF" / "native-image" / "com.amazonaws/aws-lambda-java-runtime-interface-client/resource-config.json"

It says it cannot find the two mentioned files, I then tried to add them as resources with full path but still got the same error when testing the lambda in the console...

"-H:IncludeResources="+baseDirectory.value / "src" / "main" / "resources" / "META-INF" / "resources" / "aws-lambda-runtime-interface-client.glibc.so","-H:IncludeResources="+baseDirectory.value / "src" / "main" / "resources" / "META-INF" / "resources" / "aws-lambda-runtime-interface-client.musl.so"

So somehow I may have missed up when converting the java / maven example to scala + sbt :-(

Been struggling quite a bit so would really love to get it working, Now I try with our own implementation of custom runtime, but that lacks many of the features and support for lambda that this project should provide

Thanks once again
Steffen

@msailes
Copy link
Contributor Author

msailes commented Apr 5, 2022

I don't know much about sbt, the maven plugin just knows to look in a set location. I'm guessing that's different for your situation. I would recommend asking in the GraalVM slack, they have a channel just for native-image.

https://www.graalvm.org/slack-invitation/

@stejsj
Copy link

stejsj commented Apr 5, 2022

@msailes thank you will try that

Comment on lines +1 to +13
[
{
"name":"com.amazonaws.services.lambda.runtime.LambdaRuntime",
"methods":[{"name":"<init>","parameterTypes":[] }],
"fields":[{"name":"logger"}],
"allPublicMethods":true
},
{
"name":"com.amazonaws.services.lambda.runtime.LambdaRuntimeInternal",
"methods":[{"name":"<init>","parameterTypes":[] }],
"allPublicMethods":true
}
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file needed if we have the dynamic Feature?

Comment on lines +1 to +8
{
"resources":{
"includes":[
{"pattern":"\\Qaws-lambda-runtime-interface-client.glibc.so\\E"},
{"pattern":"\\Qaws-lambda-runtime-interface-client.musl.so\\E"}
]},
"bundles":[]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be dynamically generated?

Comment on lines +1 to +18
[
{
"name":"java.lang.Void",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"java.util.Collections$UnmodifiableMap",
"fields":[{"name":"m"}]
},
{
"name":"jdk.internal.module.IllegalAccessLogger",
"fields":[{"name":"logger"}]
},
{
"name":"sun.misc.Unsafe",
"fields":[{"name":"theUnsafe"}]
}
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to define reflect-config for JDK internal methods and classes?

&& rm -rf /var/cache/yum


ENV GRAAL_VERSION 21.1.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we share this value with the one we define in pom.xml?

Comment on lines +14 to +25
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-runtime-interface-client</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>3.9.0</version>
</dependency>
</dependencies>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outdated dependencies

{
try{
//test to make sure all events are available
Class.forName("com.amazonaws.services.lambda.runtime.events.CloudFrontEvent");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness, this handler should ensure that all methods/classes that are accessible outside of the native-image are also accessible within the native-image. Maybe we could achieve this by running a JAR handler before this one to generate a list of all reachable entities and pass this in as an event payload to this function handler, that will in turn try to load them all

Comment on lines +4 to +9
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true,
"allDeclaredClasses": true,
"allPublicClasses": true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need allDeclared as opposed to just allPublic?

Comment on lines +28 to +30
public class LambdaEventsGraalVMFeature implements Feature {

public static final String EVENTS_PACKAGE_NAME = "com.amazonaws.services.lambda.runtime.events";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make this generic enough for it to be reused across all our libraries in this project, and move it out of the runtime addressable scope. It should be a build-only class that is not exposed in the library.

This is essentially boilerplate code that will traverse our libraries and determine what the appropriate native-image config is, so we don't really need a copy of it per project.

Comment on lines +1 to +11
[
{
"name":"com.amazonaws.services.lambda.runtime.api.client.runtimeapi.LambdaRuntimeClientException",
"methods":[{"name":"<init>","parameterTypes":["java.lang.String","int"] }]
},
{
"name":"com.amazonaws.services.lambda.runtime.api.client.runtimeapi.InvocationRequest",
"fields":[{"name":"id"}, {"name":"invokedFunctionArn"}, {"name":"deadlineTimeInMs"}, {"name":"xrayTraceId"}, {"name":"clientContext"}, {"name":"cognitoIdentity"}, {"name":"content"}],
"allPublicMethods":true
}
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be auto-generated like reflect-config.json?

Comment on lines +59 to +64
build:
commands:
- set -x
- echo "Running Image ${IMAGE_TAG}"
- docker network create "${OS_DISTRIBUTION}-network"
- >
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some parts of this script have been refactored, we should update this

@msailes msailes reopened this Aug 16, 2022
@anton-stepanof anton-stepanof deleted the branch aws:master January 3, 2023 18:00
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

Successfully merging this pull request may close these issues.

6 participants