From c3c767dd12f8e53db2844ba2d610ae4363189fd5 Mon Sep 17 00:00:00 2001 From: BaibhavVishal123 Date: Tue, 20 Jul 2021 22:07:05 +0530 Subject: [PATCH 1/2] Updating Readme Issue 1 Updating pom Issue 6, 8, 15 Updating resources Issue 16 Updating for Lambda Timeout in template.yml Adding Postman for direct Usage --- .gitignore | 7 ++ README.md | 8 +- pom.xml | 4 +- src/postman/collection.json | 117 ++++++++++++++++++ src/test/resources/test_environment_mac.json | 10 +- .../resources/test_environment_windows.json | 10 +- template.yaml | 2 +- 7 files changed, 144 insertions(+), 14 deletions(-) create mode 100644 .gitignore create mode 100644 src/postman/collection.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c4ba347 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/target/ +.settings/* +.classpath +.project +.aws-sam/* +dependency-reduced-pom.xml +.factorypath \ No newline at end of file diff --git a/README.md b/README.md index f9f4c75..2209063 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,13 @@ mvn package ### Local development **Invoking function locally through local API Gateway** -1. Start DynamoDB Local in a Docker container. `docker run -p 8000:8000 amazon/dynamodb-local` +1. Start DynamoDB Local in a Docker container. +`docker run -p 8000:8000 amazon/dynamodb-local` + +[Issue 1](https://github.com/aws-samples/aws-sam-java-rest/issues/1) Here is another example, if you want to play around the container +``` +docker run -it --rm -v %cd%:/home/dynamodblocal/data -p 8000:8000 amazon/dynamodb-local -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb -dbPath ./data +``` 2. Create the DynamoDB table. `aws dynamodb create-table --table-name orders_table --attribute-definitions AttributeName=orderId,AttributeType=S --key-schema AttributeName=orderId,KeyType=HASH --billing-mode PAY_PER_REQUEST --endpoint-url http://localhost:8000` 3. Start the SAM local API. - On a Mac: `sam local start-api --env-vars src/test/resources/test_environment_mac.json` diff --git a/pom.xml b/pom.xml index 0cd0aad..5ade9ce 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,7 @@ 2.22.0 3.0.5 3.0.0-M2 - 0.8.1 + 0.8.5 0.26.1 @@ -333,7 +333,7 @@ ${failsafe.plugin.version} - http://localhost:8000 + http://localhost:8005 diff --git a/src/postman/collection.json b/src/postman/collection.json new file mode 100644 index 0000000..a07db9c --- /dev/null +++ b/src/postman/collection.json @@ -0,0 +1,117 @@ +{ + "info": { + "_postman_id": "bfdc95c0-4714-497c-b090-78e9f7ade3d8", + "name": "aws-sam-java-rest requests", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "get order", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://127.0.0.1:3000/orders/{{orderId}}", + "protocol": "http", + "host": [ + "127", + "0", + "0", + "1" + ], + "port": "3000", + "path": [ + "orders", + "{{orderId}}" + ] + } + }, + "response": [] + }, + { + "name": "update order", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "name": "Content-Type", + "value": "application/json", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n\t\"orderId\": \"{{orderId}}\",\n\t\"customerId\": \"1\",\n\t\"preTaxAmount\": 20,\n\t\"postTaxAmount\": 24,\n\t\"version\": 1\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://127.0.0.1:3000/orders/{{orderId}}", + "protocol": "http", + "host": [ + "127", + "0", + "0", + "1" + ], + "port": "3000", + "path": [ + "orders", + "{{orderId}}" + ] + } + }, + "response": [] + }, + { + "name": "get orders", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://127.0.0.1:3000/orders", + "protocol": "http", + "host": [ + "127", + "0", + "0", + "1" + ], + "port": "3000", + "path": [ + "orders" + ] + } + }, + "response": [] + }, + { + "name": "delete order", + "request": { + "method": "DELETE", + "header": [], + "url": { + "raw": "http://127.0.0.1:3000/orders/{{orderId}}", + "protocol": "http", + "host": [ + "127", + "0", + "0", + "1" + ], + "port": "3000", + "path": [ + "orders", + "{{orderId}}" + ] + } + }, + "response": [] + } + ], + "protocolProfileBehavior": {} +} \ No newline at end of file diff --git a/src/test/resources/test_environment_mac.json b/src/test/resources/test_environment_mac.json index d48351d..ee9d952 100644 --- a/src/test/resources/test_environment_mac.json +++ b/src/test/resources/test_environment_mac.json @@ -1,22 +1,22 @@ { "GetOrderFunction": { - "ENDPOINT_OVERRIDE": "http://docker.for.mac.localhost:8000", + "ENDPOINT_OVERRIDE": "http://host.docker.internal:8000", "TABLE_NAME": "orders_table" }, "GetOrdersFunction": { - "ENDPOINT_OVERRIDE": "http://docker.for.mac.localhost:8000", + "ENDPOINT_OVERRIDE": "http://host.docker.internal:8000", "TABLE_NAME": "orders_table" }, "UpdateOrderFunction": { - "ENDPOINT_OVERRIDE": "http://docker.for.mac.localhost:8000", + "ENDPOINT_OVERRIDE": "http://host.docker.internal:8000", "TABLE_NAME": "orders_table" }, "DeleteOrderFunction": { - "ENDPOINT_OVERRIDE": "http://docker.for.mac.localhost:8000", + "ENDPOINT_OVERRIDE": "http://host.docker.internal:8000", "TABLE_NAME": "orders_table" }, "CreateOrderFunction": { - "ENDPOINT_OVERRIDE": "http://docker.for.mac.localhost:8000", + "ENDPOINT_OVERRIDE": "http://host.docker.internal:8000", "TABLE_NAME": "orders_table" } } diff --git a/src/test/resources/test_environment_windows.json b/src/test/resources/test_environment_windows.json index 03739be..ee9d952 100644 --- a/src/test/resources/test_environment_windows.json +++ b/src/test/resources/test_environment_windows.json @@ -1,22 +1,22 @@ { "GetOrderFunction": { - "ENDPOINT_OVERRIDE": "http://docker.for.windows.localhost:8000", + "ENDPOINT_OVERRIDE": "http://host.docker.internal:8000", "TABLE_NAME": "orders_table" }, "GetOrdersFunction": { - "ENDPOINT_OVERRIDE": "http://docker.for.windows.localhost:8000", + "ENDPOINT_OVERRIDE": "http://host.docker.internal:8000", "TABLE_NAME": "orders_table" }, "UpdateOrderFunction": { - "ENDPOINT_OVERRIDE": "http://docker.for.windows.localhost:8000", + "ENDPOINT_OVERRIDE": "http://host.docker.internal:8000", "TABLE_NAME": "orders_table" }, "DeleteOrderFunction": { - "ENDPOINT_OVERRIDE": "http://docker.for.windows.localhost:8000", + "ENDPOINT_OVERRIDE": "http://host.docker.internal:8000", "TABLE_NAME": "orders_table" }, "CreateOrderFunction": { - "ENDPOINT_OVERRIDE": "http://docker.for.windows.localhost:8000", + "ENDPOINT_OVERRIDE": "http://host.docker.internal:8000", "TABLE_NAME": "orders_table" } } diff --git a/template.yaml b/template.yaml index a7301c1..1854a37 100644 --- a/template.yaml +++ b/template.yaml @@ -8,7 +8,7 @@ Description: > # More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst Globals: Function: - Timeout: 20 + Timeout: 300 MemorySize: 512 Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object Variables: From 92a963fdb0bba3c08e9d392dc97eca88b4b89366 Mon Sep 17 00:00:00 2001 From: BaibhavVishal123 Date: Tue, 20 Jul 2021 22:41:07 +0530 Subject: [PATCH 2/2] Using PR11 --- README.md | 1 + src/{ => test/resources}/postman/collection.json | 0 2 files changed, 1 insertion(+) rename src/{ => test/resources}/postman/collection.json (100%) diff --git a/README.md b/README.md index 2209063..92e2244 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ docker run -it --rm -v %cd%:/home/dynamodblocal/data -p 8000:8000 amazon/dynamod If the previous command ran successfully you should now be able to hit the following local endpoint to invoke the functions rooted at `http://localhost:3000/orders` +4. To test APIs' in Postman, import Collection from `src/resources/postman/collection.json` **SAM CLI** is used to emulate both Lambda and API Gateway locally and uses our `template.yaml` to understand how to bootstrap this environment (runtime, where the source code is, etc.) - The diff --git a/src/postman/collection.json b/src/test/resources/postman/collection.json similarity index 100% rename from src/postman/collection.json rename to src/test/resources/postman/collection.json