Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/target/
.settings/*
.classpath
.project
.aws-sam/*
dependency-reduced-pom.xml
.factorypath
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<failsafe.plugin.version>2.22.0</failsafe.plugin.version>
<findbugs.maven.plugin.version>3.0.5</findbugs.maven.plugin.version>
<maven.enforcer.plugin.version>3.0.0-M2</maven.enforcer.plugin.version>
<jacoco.maven.plugin.version>0.8.1</jacoco.maven.plugin.version>
<jacoco.maven.plugin.version>0.8.5</jacoco.maven.plugin.version>
<docker.maven.plugin.version>0.26.1</docker.maven.plugin.version>
</properties>

Expand Down Expand Up @@ -333,7 +333,7 @@
<version>${failsafe.plugin.version}</version>
<configuration>
<environmentVariables>
<ENDPOINT_OVERRIDE>http://localhost:8000</ENDPOINT_OVERRIDE>
<ENDPOINT_OVERRIDE>http://localhost:8005</ENDPOINT_OVERRIDE>
</environmentVariables>
</configuration>
<executions>
Expand Down
117 changes: 117 additions & 0 deletions src/test/resources/postman/collection.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
10 changes: 5 additions & 5 deletions src/test/resources/test_environment_mac.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
10 changes: 5 additions & 5 deletions src/test/resources/test_environment_windows.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
2 changes: 1 addition & 1 deletion template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down