diff --git a/java/api-cors-lambda-crud-dynamodb/README.md b/java/api-cors-lambda-crud-dynamodb/README.md index 9da135ed2..8bbfc7895 100644 --- a/java/api-cors-lambda-crud-dynamodb/README.md +++ b/java/api-cors-lambda-crud-dynamodb/README.md @@ -4,12 +4,14 @@ This is an example of a CDK program written in Java. ## Building -To build this app, run `mvn package`. This will download the required -dependencies to compile the Java code and create jar for associated lambda code. +To build this app, run `mvn compile`. This will download the required +dependencies to compile the Java code and create jar for associated software.amazon.awscdk.examples.lambda code. You can use your IDE to write code and unit tests, but you will need to use the CDK toolkit if you wish to synthesize/deploy stacks. +If you need to modify the lambda code then do mvn package and copy the +jar file to lib directory in the parent module ## CDK Toolkit The [`cdk.json`](./cdk.json) file in the root of this repository includes diff --git a/java/api-cors-lambda-crud-dynamodb/cdk.json b/java/api-cors-lambda-crud-dynamodb/cdk.json index 09a0b612e..89d79b0c6 100644 --- a/java/api-cors-lambda-crud-dynamodb/cdk.json +++ b/java/api-cors-lambda-crud-dynamodb/cdk.json @@ -1,3 +1,3 @@ { - "app": "mvn exec:java -Dexec.mainClass=software.amazon.awscdk.examples.CorsLambdaCrudDynamodbApp" + "app": "mvn exec:java -pl cdk -Dexec.mainClass=software.amazon.awscdk.examples.CorsLambdaCrudDynamodbApp" } diff --git a/java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/CorsLambdaCrudDynamodbApp.java b/java/api-cors-lambda-crud-dynamodb/cdk/src/main/java/software/amazon/awscdk/examples/CorsLambdaCrudDynamodbApp.java similarity index 100% rename from java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/CorsLambdaCrudDynamodbApp.java rename to java/api-cors-lambda-crud-dynamodb/cdk/src/main/java/software/amazon/awscdk/examples/CorsLambdaCrudDynamodbApp.java diff --git a/java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/CorsLambdaCrudDynamodbStack.java b/java/api-cors-lambda-crud-dynamodb/cdk/src/main/java/software/amazon/awscdk/examples/CorsLambdaCrudDynamodbStack.java similarity index 93% rename from java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/CorsLambdaCrudDynamodbStack.java rename to java/api-cors-lambda-crud-dynamodb/cdk/src/main/java/software/amazon/awscdk/examples/CorsLambdaCrudDynamodbStack.java index 04acbcc2d..c161e58c1 100644 --- a/java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/CorsLambdaCrudDynamodbStack.java +++ b/java/api-cors-lambda-crud-dynamodb/cdk/src/main/java/software/amazon/awscdk/examples/CorsLambdaCrudDynamodbStack.java @@ -49,15 +49,15 @@ public CorsLambdaCrudDynamodbStack(final Construct parent, final String name) { Function getOneItemFunction = new Function(this, "getOneItemFunction", - getLambdaFunctionProps(lambdaEnvMap, "software.amazon.awscdk.examples.lambda.GetOneItem")); + getLambdaFunctionProps(lambdaEnvMap, "software.amazon.awscdk.examples.software.amazon.awscdk.examples.lambda.GetOneItem")); Function getAllItemsFunction = new Function(this, "getAllItemsFunction", - getLambdaFunctionProps(lambdaEnvMap, "software.amazon.awscdk.examples.lambda.GetAllItems")); + getLambdaFunctionProps(lambdaEnvMap, "software.amazon.awscdk.examples.software.amazon.awscdk.examples.lambda.GetAllItems")); Function createItemFunction = new Function(this, "createItemFunction", - getLambdaFunctionProps(lambdaEnvMap, "software.amazon.awscdk.examples.lambda.CreateItem")); + getLambdaFunctionProps(lambdaEnvMap, "software.amazon.awscdk.examples.software.amazon.awscdk.examples.lambda.CreateItem")); Function updateItemFunction = new Function(this, "updateItemFunction", - getLambdaFunctionProps(lambdaEnvMap, "software.amazon.awscdk.examples.lambda.UpdateItem")); + getLambdaFunctionProps(lambdaEnvMap, "software.amazon.awscdk.examples.software.amazon.awscdk.examples.lambda.UpdateItem")); Function deleteItemFunction = new Function(this, "deleteItemFunction", - getLambdaFunctionProps(lambdaEnvMap, "software.amazon.awscdk.examples.lambda.DeleteItem")); + getLambdaFunctionProps(lambdaEnvMap, "software.amazon.awscdk.examples.software.amazon.awscdk.examples.lambda.DeleteItem")); @@ -136,7 +136,7 @@ private void addCorsOptions(IResource item) { private FunctionProps getLambdaFunctionProps(Map lambdaEnvMap, String handler) { return FunctionProps.builder() - .code(Code.fromAsset("target/cors-lambda-crud-dynamodb-1.0.0-jar-with-dependencies.jar")) + .code(Code.fromAsset("./lib/lambda-1.0.0-jar-with-dependencies.jar")) .handler(handler) .runtime(Runtime.JAVA_8) .environment(lambdaEnvMap) diff --git a/java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/CreateItem.java b/java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/CreateItem.java similarity index 95% rename from java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/CreateItem.java rename to java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/CreateItem.java index b74a3f889..d95fa8d0e 100644 --- a/java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/CreateItem.java +++ b/java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/CreateItem.java @@ -23,7 +23,7 @@ public class CreateItem implements RequestHandler, GatewayRes @Override public GatewayResponse handleRequest(Map input, Context context) { LambdaLogger logger = context.getLogger(); - logger.log("Inside lambda: getOneItem "+input.getClass()+ " data:"+input); + logger.log("Inside software.amazon.awscdk.examples.lambda: getOneItem "+input.getClass()+ " data:"+input); String body = (String)input.get("body"); diff --git a/java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/DeleteItem.java b/java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/DeleteItem.java similarity index 93% rename from java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/DeleteItem.java rename to java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/DeleteItem.java index 96a86c9cf..049f9e798 100644 --- a/java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/DeleteItem.java +++ b/java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/DeleteItem.java @@ -16,7 +16,7 @@ public class DeleteItem implements RequestHandler, GatewayRes @Override public GatewayResponse handleRequest(Map input, Context context) { LambdaLogger logger = context.getLogger(); - logger.log("Inside lambda: getOneItem "+input.getClass()+ " data:"+input); + logger.log("Inside software.amazon.awscdk.examples.lambda: getOneItem "+input.getClass()+ " data:"+input); Map pathParameters = (Map)input.get("pathParameters"); Map headers = new HashMap<>(); diff --git a/java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/GatewayResponse.java b/java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/GatewayResponse.java similarity index 100% rename from java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/GatewayResponse.java rename to java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/GatewayResponse.java diff --git a/java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/GetAllItems.java b/java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/GetAllItems.java similarity index 93% rename from java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/GetAllItems.java rename to java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/GetAllItems.java index 19cd0bcfb..81389ca71 100644 --- a/java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/GetAllItems.java +++ b/java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/GetAllItems.java @@ -17,7 +17,7 @@ public class GetAllItems implements RequestHandler{ @Override public GatewayResponse handleRequest(Object input, Context context) { LambdaLogger logger = context.getLogger(); - logger.log("Inside lambda: getAllItems "); + logger.log("Inside software.amazon.awscdk.examples.lambda: getAllItems "); String output = getData(context); diff --git a/java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/GetOneItem.java b/java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/GetOneItem.java similarity index 93% rename from java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/GetOneItem.java rename to java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/GetOneItem.java index 0dc7c0b90..520388fe5 100644 --- a/java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/GetOneItem.java +++ b/java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/GetOneItem.java @@ -16,7 +16,7 @@ public class GetOneItem implements RequestHandler, GatewayRes @Override public GatewayResponse handleRequest(Map input, Context context) { LambdaLogger logger = context.getLogger(); - logger.log("Inside lambda: getOneItem "+input.getClass()+ " data:"+input); + logger.log("Inside software.amazon.awscdk.examples.lambda: getOneItem "+input.getClass()+ " data:"+input); Map pathParameters = (Map)input.get("pathParameters"); String id=(String)pathParameters.get("id"); diff --git a/java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/UpdateItem.java b/java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/UpdateItem.java similarity index 95% rename from java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/UpdateItem.java rename to java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/UpdateItem.java index 8e2bfa181..9e7933f2b 100644 --- a/java/api-cors-lambda-crud-dynamodb/src/main/java/software/amazon/awscdk/examples/lambda/UpdateItem.java +++ b/java/api-cors-lambda-crud-dynamodb/lambda/src/main/java/software/amazon/awscdk/examples/lambda/UpdateItem.java @@ -20,7 +20,7 @@ public class UpdateItem implements RequestHandler, GatewayRes @Override public GatewayResponse handleRequest(Map input, Context context) { LambdaLogger logger = context.getLogger(); - logger.log("Inside lambda: getOneItem "+input.getClass()+ " data:"+input); + logger.log("Inside software.amazon.awscdk.examples.lambda: getOneItem "+input.getClass()+ " data:"+input); Map pathParameters = (Map)input.get("pathParameters"); String id=(String)pathParameters.get("id"); diff --git a/java/api-cors-lambda-crud-dynamodb/pom.xml b/java/api-cors-lambda-crud-dynamodb/pom.xml index c096c9416..3df7ae972 100644 --- a/java/api-cors-lambda-crud-dynamodb/pom.xml +++ b/java/api-cors-lambda-crud-dynamodb/pom.xml @@ -5,7 +5,12 @@ com.amazonaws.cdk cors-lambda-crud-dynamodb + pom 1.0.0 + + lambda + cdk + UTF-8 @@ -33,14 +38,14 @@ - com.amazonaws.cdk.examples.CorsLambdaCrudDynamodbStack + com.amazonaws.cdk.examples.CorsLambdaCrudDynamodbApp - make-assembly - package + make-assembly + package single @@ -51,77 +56,5 @@ - - - software.amazon.awscdk - core - [1.17.0.DEVPREVIEW, 2) - - - software.amazon.awscdk - apigateway - [1.17.0.DEVPREVIEW, 2) - - - - software.amazon.awscdk - dynamodb - [1.17.0.DEVPREVIEW, 2) - - - software.amazon.awscdk - lambda - [1.17.0.DEVPREVIEW, 2) - - - - com.amazonaws - aws-lambda-java-core - 1.2.0 - - - - software.amazon.awssdk - dynamodb - - - - - com.google.code.gson - gson - 2.8.6 - - - - - junit - junit - 4.12 - test - - - org.hamcrest - hamcrest-core - - - - - org.hamcrest - hamcrest-library - 1.3 - test - - - - - - software.amazon.awssdk - bom - 2.10.24 - pom - import - - - diff --git a/java/lambda-cron/src/main/java/software/amazon/awscdk/examples/LambdaCronApp.java b/java/lambda-cron/src/main/java/software/amazon/awscdk/examples/LambdaCronApp.java index 43cd35795..bdcd7bcd9 100644 --- a/java/lambda-cron/src/main/java/software/amazon/awscdk/examples/LambdaCronApp.java +++ b/java/lambda-cron/src/main/java/software/amazon/awscdk/examples/LambdaCronApp.java @@ -6,7 +6,7 @@ public class LambdaCronApp { public static void main(final String[] args) { App app = new App(); - new LambdaCronStack(app, "cdk-lambda-cron-example"); + new LambdaCronStack(app, "cdk-software.amazon.awscdk.examples.lambda-cron-example"); app.synth(); } diff --git a/java/lambda-cron/src/main/java/software/amazon/awscdk/examples/LambdaCronStack.java b/java/lambda-cron/src/main/java/software/amazon/awscdk/examples/LambdaCronStack.java index 50fb6ae41..46500b25a 100644 --- a/java/lambda-cron/src/main/java/software/amazon/awscdk/examples/LambdaCronStack.java +++ b/java/lambda-cron/src/main/java/software/amazon/awscdk/examples/LambdaCronStack.java @@ -20,7 +20,7 @@ class LambdaCronStack extends Stack { public LambdaCronStack(final Construct parent, final String name) { super(parent, name); - SingletonFunction lambdaFunction = SingletonFunction.Builder.create(this, "cdk-lambda-cron") + SingletonFunction lambdaFunction = SingletonFunction.Builder.create(this, "cdk-software.amazon.awscdk.examples.lambda-cron") .description("Lambda which prints \"I'm running\"") .code(Code.fromInline( "def main(event, context):\n" + @@ -31,7 +31,7 @@ public LambdaCronStack(final Construct parent, final String name) { .uuid(UUID.randomUUID().toString()) .build(); - Rule rule = Rule.Builder.create(this, "cdk-lambda-cron-rule") + Rule rule = Rule.Builder.create(this, "cdk-software.amazon.awscdk.examples.lambda-cron-rule") .description("Run every day at 6PM UTC") .schedule(Schedule.expression("cron(0 18 ? * MON-FRI *)")) .build(); diff --git a/java/lambda-cron/src/test/java/software/amazon/awscdk/examples/LambdaCronStackTest.java b/java/lambda-cron/src/test/java/software/amazon/awscdk/examples/LambdaCronStackTest.java index 4ec6ce032..4eede8f27 100644 --- a/java/lambda-cron/src/test/java/software/amazon/awscdk/examples/LambdaCronStackTest.java +++ b/java/lambda-cron/src/test/java/software/amazon/awscdk/examples/LambdaCronStackTest.java @@ -22,7 +22,7 @@ public class LambdaCronStackTest { @Before public void setUp() throws IOException { App app = new App(); - Stack stack = new LambdaCronStack(app, "lambdaResource-cdk-lambda-cron"); + Stack stack = new LambdaCronStack(app, "lambdaResource-cdk-software.amazon.awscdk.examples.lambda-cron"); actualStack = toCloudFormationJson(stack).path("Resources"); expectedStack = TestUtils.fromFileResource(getClass().getResource("testCronLambdaExpected.json")).path("Resources"); }