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..92e2244 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` @@ -83,6 +89,7 @@ mvn package 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/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/test/resources/postman/collection.json b/src/test/resources/postman/collection.json new file mode 100644 index 0000000..a07db9c --- /dev/null +++ b/src/test/resources/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: