You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2021/03/26 07:46:21 UTC

[GitHub] [flink-statefun-playground] igalshilman commented on a change in pull request #10: [FLINK-21828] Add a tutorial for AWS Lambda function deployments

igalshilman commented on a change in pull request #10:
URL: https://github.com/apache/flink-statefun-playground/pull/10#discussion_r602058022



##########
File path: deployments/aws-lambda/src/main/java/org/apache/flink/statefun/playground/aws/GreeterFn.java
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flink.statefun.playground.aws;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.flink.statefun.sdk.java.Context;
+import org.apache.flink.statefun.sdk.java.StatefulFunction;
+import org.apache.flink.statefun.sdk.java.StatefulFunctionSpec;
+import org.apache.flink.statefun.sdk.java.TypeName;
+import org.apache.flink.statefun.sdk.java.message.Message;
+
+public final class GreeterFn implements StatefulFunction {
+
+  static final TypeName TYPENAME = TypeName.typeNameOf("aws.lambda.example", "greeter");
+  static final StatefulFunctionSpec SPEC =
+      StatefulFunctionSpec.builder(TYPENAME).withSupplier(GreeterFn::new).build();
+
+  @Override
+  public CompletableFuture<Void> apply(Context context, Message message) {
+    System.out.println("Welcome, " + message.asUtf8String() + "!");

Review comment:
       Can you replace that with .rawValue converted to UTF8 string?
   So that if folks will take it as a baseline, they won't be surprised.

##########
File path: deployments/aws-lambda/README.md
##########
@@ -0,0 +1,46 @@
+# Serving StateFun Functions with AWS Lambda
+
+This tutorial is intended to demonstrate how you can serve your functions with [AWS Lambda](https://aws.amazon.com/lambda/),
+a popular FaaS platform for running code with serverless deployments. With the rapid elasticity and simplicity of FaaS
+platforms, this makes it very easy to scale out your StateFun functions.
+
+If you are still new to StateFun and unfamiliar with the overall architecture of a StateFun application, we highly
+recommend to first take a look at some of the demo tutorials under the language-specific directories (such as the
+Greeter examples for [Java](../../java/greeter) or [Python](../../python/greeter)).
+
+## Deployment Steps
+
+### Build an AWS Lambda code package
+
+We're demonstrating Java here, so the code package you submit to AWS Lambda will be a JAR.
+
+```
+$ mvn clean install
+# or, if you don't have Maven installed and would like to use Docker:
+$ docker run -it --rm --name build -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.6.3-jdk-8 mvn clean install
+```
+
+This builds an uber JAR containing all required dependencies by the AWS Lambda runtime at `target/aws-lambda-example*.jar`.
+
+### Deploy to AWS Lambda
+
+- Upload this JAR to AWS Lambda. You can do this [manually via the web console](https://docs.aws.amazon.com/lambda/latest/dg/getting-started-create-function.html),
+or using the [AWS CLI](https://aws.amazon.com/cli/).
+
+- The handler method should be set to `org.apache.flink.statefun.playground.aws.GreeterAwsLambdaHandler::handleRequest`.
+That refers to the entrypoint handle method you'll find in the [code](src/main/java/org/apache/flink/statefun/playground/aws/GreeterAwsLambdaHandler.java).
+
+- After you upload and create the new AWS Lambda function, configure it to be
+[triggered by an API Gateway HTTP endpoint](https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html).
+
+After completing this step, you should now have a HTTP endpoint URL (e.g. https://abcdxyz.execute-api.us-west-1.amazonaws.com/default/my-aws-lambda-fn)
+for invoking your StateFun functions.
+
+### Configure StateFun Module Specification
+
+The AWS Lambda endpoint URL should be configured as a function endpoint in your [Module Specification]().

Review comment:
       can you add here a minimal snippet of the endpoint spec, that follows the example url pointed from above?
   Probably folks would like to copy paste this section.
   
   While doing so, I think it's also important to adjust the default timeouts to be slightly longer than 30 seconds. As it seems to be default. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org