Skip to content

Commit

Permalink
Merge pull request #7619 from patriot1burke/lambda-tmpdir
Browse files Browse the repository at this point in the history
tmpdir system properties Issue #7605
  • Loading branch information
patriot1burke authored Mar 7, 2020
2 parents 49d0129 + 87fd094 commit 83d5587
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
35 changes: 26 additions & 9 deletions docs/src/main/asciidoc/amazon-lambda.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,10 @@ LAMBDA_ROLE_ARN="arn:aws:iam::1234567890:role/lambda-role"
== Create the function

The `manage.sh` script is for managing your lambda using the AWS Lambda Java runtime. This script is provided only for
your convenience. Should you choose to use Amazon provided tools, you can freely skip these sections and consult the
appropriate Amazon documentation.
your convenience. Examine the output of the `manage.sh` script if you want to learn what aws commands are executed
to create, delete, and update your lambdas.

`manage.sh` supports four operation: `create`, `delete`, `update`, and `invoke`. You can create your function using
the following command:
`manage.sh` supports four operation: `create`, `delete`, `update`, and `invoke`. You can create your function using the following command:

[source, subs=attributes+]
----
Expand Down Expand Up @@ -186,8 +185,14 @@ sh manage.sh update
== Deploy to AWS Lambda Custom (native) Runtime

If you want a lower memory footprint and faster initialization times for your lambda, you can compile your Java
code to a native executable. Just make sure to rebuild your project with the `-Pnative` switch. If you are building
on a non-linux system, you will need to also pass in a property instructing quarkus to use a docker build as Amazon
code to a native executable. Just make sure to rebuild your project with the `-Pnative` switch.

[source, subs=attributes+]
----
mvn clean install -Pnative
----

If you are building on a non-linux system, you will need to also pass in a property instructing quarkus to use a docker build as Amazon
Lambda requires linux binaries. You can do this by passing this property to your maven build:
`-Dnative-image.docker-build=true`. This requires you to have docker installed locally, however.

Expand All @@ -196,10 +201,11 @@ Lambda requires linux binaries. You can do this by passing this property to you
./mvnw clean install -Pnative -Dnative-image.docker-build=true
----

This will compile and create a native executable image. It also generates a zip file `target/function.zip`.
Either of these commands will compile and create a native executable image. It also generates a zip file `target/function.zip`.
This zip file contains your native executable image renamed to `bootstrap`. This is a requirement of Amazon Lambda
Custom Runtime. If you are building on Linux, the `native-image.docker-build` property is mildly redundant but its primary
cost is a slightly longer build cycle.
Custom Runtime.



The instructions here are exactly as above with one change: you'll need to add `native` as the first parameter to the
`manage.sh` script:
Expand All @@ -213,6 +219,17 @@ As above, commands can be stacked. The only requirement is that `native` be the
to work with native image builds. The script will take care of the rest of the details necessary to manage your native
image function deployments.

Examine the output of the `manage.sh` script if you want to learn what aws commands are executed
to create, delete, and update your lambdas.

One thing to note about the create command for native is that the `aws lambda create-function`
call must set a specific environment variable:

[source, subs=attributes+]
----
--environment 'Variables={DISABLE_SIGNAL_HANDLERS=true}'
----

== Examine the POM

If you want to adapt an existing project to use Quarkus's Amazon Lambda extension, there are a couple
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ void ipv4Only(BuildProducer<SystemPropertyBuildItem> systemProperty) {
systemProperty.produce(new SystemPropertyBuildItem("java.net.preferIPv4Stack", "true"));
}

@BuildStep
void tmpdirs(BuildProducer<SystemPropertyBuildItem> systemProperty,
LaunchModeBuildItem launchModeBuildItem) {
LaunchMode mode = launchModeBuildItem.getLaunchMode();
if (mode.isDevOrTest()) {
return; // just in case we're on windows.
}
systemProperty.produce(new SystemPropertyBuildItem("java.io.tmpdir", "/tmp"));
systemProperty.produce(new SystemPropertyBuildItem("vertx.cacheDirBase", "/tmp/vertx"));
}

@BuildStep
@Record(value = ExecutionTime.RUNTIME_INIT)
void enableNativeEventLoop(LambdaBuildTimeConfig config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

function cmd_create() {
echo Creating function
set -x
aws lambda create-function \
--function-name ${FUNCTION_NAME} \
--zip-file ${ZIP_FILE} \
Expand All @@ -13,11 +14,13 @@ function cmd_create() {

function cmd_delete() {
echo Deleting function
set -x
aws lambda delete-function --function-name ${FUNCTION_NAME}
}

function cmd_invoke() {
echo Invoking function
set -x
aws lambda invoke response.txt \
--function-name ${FUNCTION_NAME} \
--payload file://payload.json \
Expand All @@ -28,6 +31,7 @@ function cmd_invoke() {

function cmd_update() {
echo Updating function
set -x
aws lambda update-function-code \
--function-name ${FUNCTION_NAME} \
--zip-file ${ZIP_FILE}
Expand Down Expand Up @@ -64,6 +68,7 @@ fi
while [ "$1" ]
do
eval cmd_${1}
{ set +x; } 2>/dev/null
shift
done

0 comments on commit 83d5587

Please sign in to comment.