ちょっとハマったのでメモ。JavaはMavenでコンパイルします。
Test.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | package com.example; import java.util.Iterator; import java.util.Map; import com.amazonaws.services.lambda.runtime.Context; public class Test { //http://stackoverflow.com/questions/35545642/error-executing-hello-world-for-aws-lambda-in-java public String handler(Map<String,Object> input, Context context){ String ret=""; Iterator<String> ite=input.keySet().iterator(); while(ite.hasNext()){ String key=ite.next(); String val=input.get(key).toString(); ret+="("+key+","+val+"),"; } return ret; } } |
pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>test</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>Test</name> <url>http://example.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-lambda-java-core</artifactId> <version>1.0.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.3</version> <configuration> <createDependencyReducedPom>false</createDependencyReducedPom> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> |
コンパイル
1 | mvn package |
Lambdaへアップロード
- zipファイルをアップロード
- Configulationを設定
Runtime | Java 8 |
Handler | com.example.Test::handler |
これで動きます。テストの際に与えるパラメタの値が表示されます