-
Notifications
You must be signed in to change notification settings - Fork 20
Test and develop against Dynamodb Local #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0ed6bc5
Add dynamodb local setup command. Add events table
rustworthy 663046e
Add questions table
rustworthy 6f50cbf
Add test/e2e cmd to test against dynamodb local
rustworthy 70eea75
Add instructions to CONTRIBUTING.md
rustworthy 452d28e
Enable developing against local dynamodb
rustworthy bba72c6
Add Web UI for DynamoDB Local
rustworthy 5d20863
Refactor backend block in main
rustworthy a2be2bc
Put dynamodb plus indexes cration to script
rustworthy c6a0c6d
Improve run-dynamodb-local script
rustworthy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| /target | ||
| /target | ||
| /dynamodb-data | ||
| Makefile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| if ! [ -x "$(command -v docker)" ]; then | ||
| echo '❌ Error: please make sure docker is installed and is in the PATH' >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! [ -x "$(command -v aws)" ]; then | ||
| echo '❌ Error: please make sure AWS CLI is installed and is in the PATH' >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # AWS CLI wants us to either run `aws configure` or provide the three essential variables | ||
| # from the environment. Most of us will have aws profile(s) configured on the workstation, | ||
| # but this should not be a requirement to be able to spin up and query a DynamoDB Local | ||
| # instance. This is why we are setting those variables in the current shell. Note that | ||
| # the credential values themselves do not matter, it is rather the fact that they _are_ set. | ||
| # | ||
| # see: https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-envvars.html#envvars-set | ||
| export AWS_ACCESS_KEY_ID=lorem | ||
| export AWS_SECRET_ACCESS_KEY=ipsum | ||
| export AWS_DEFAULT_REGION=us-east-1 | ||
|
|
||
| DYNAMODB_CONTAINER_NAME=dynamodb-local | ||
| DYNAMODB_ADMIN_CONTAINER_NAME=dynamodb-admin | ||
| ENDPOINT_URL=http://localhost:8000 | ||
|
|
||
| docker ps | grep ${DYNAMODB_CONTAINER_NAME} >/dev/null && | ||
| echo "🚫 Container \"${DYNAMODB_CONTAINER_NAME}\" with DynamoDB Local service is already running." && exit 0 | ||
|
|
||
| echo "🖴 Preparing volumes for DynamoDB..." | ||
| rm -rf dynamodb-data | ||
| mkdir dynamodb-data | ||
|
|
||
| echo "🚀 Spinning up a container with DynamoDB..." | ||
| ( | ||
| docker run --rm -d -v ./dynamodb-data:/home/dynamodblocal/data -p 127.0.0.1:8000:8000 \ | ||
| -w /home/dynamodblocal --name ${DYNAMODB_CONTAINER_NAME} amazon/dynamodb-local:latest \ | ||
| -jar DynamoDBLocal.jar -sharedDb -dbPath ./data | ||
| ) >/dev/null | ||
|
|
||
| while ! (AWS_ACCESS_KEY_ID=lorem AWS_SECRET_ACCESS_KEY=ipsum aws dynamodb list-tables --endpoint-url ${ENDPOINT_URL} --region us-east-1 >/dev/null); do | ||
| echo "⏳ Waiting for the database to start accepting connections..." | ||
| done | ||
|
|
||
| echo "🗒️ Creating 'events' table..." | ||
| aws dynamodb create-table \ | ||
| --table-name events \ | ||
| --attribute-definitions AttributeName=id,AttributeType=S \ | ||
| --key-schema AttributeName=id,KeyType=HASH \ | ||
| --billing-mode PAY_PER_REQUEST \ | ||
| --endpoint-url ${ENDPOINT_URL} >/dev/null | ||
|
|
||
| aws dynamodb update-time-to-live \ | ||
| --table-name events \ | ||
| --time-to-live-specification Enabled=true,AttributeName=expire \ | ||
| --endpoint-url ${ENDPOINT_URL} >/dev/null | ||
|
|
||
| echo "🗒️ Creating 'questions' table and 🚄 GSI..." | ||
| aws dynamodb create-table \ | ||
| --table-name questions \ | ||
| --attribute-definitions AttributeName=id,AttributeType=S \ | ||
| AttributeName=eid,AttributeType=S \ | ||
| AttributeName=votes,AttributeType=N \ | ||
| --key-schema AttributeName=id,KeyType=HASH \ | ||
| --global-secondary-indexes 'IndexName=top,KeySchema=[{AttributeName=eid,KeyType=HASH},{AttributeName=votes,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[answered,hidden]}' \ | ||
| --billing-mode PAY_PER_REQUEST \ | ||
| --endpoint-url ${ENDPOINT_URL} >/dev/null | ||
|
|
||
| aws dynamodb update-time-to-live \ | ||
| --table-name questions \ | ||
| --time-to-live-specification Enabled=true,AttributeName=expire \ | ||
| --endpoint-url ${ENDPOINT_URL} >/dev/null | ||
|
|
||
| echo "✅ Container \"${DYNAMODB_CONTAINER_NAME}\" with DynamoDB Local is ready!" | ||
|
|
||
| docker ps | grep ${DYNAMODB_ADMIN_CONTAINER_NAME} >/dev/null && | ||
| echo "🚫 Container "${DYNAMODB_ADMIN_CONTAINER_NAME}" with DynamoDB Admin service is already running." && | ||
| exit 0 | ||
|
|
||
| echo "🚀 Spinning up a container with DynamoDB Admin..." | ||
| (docker run -d --rm --net host --name ${DYNAMODB_ADMIN_CONTAINER_NAME} aaronshaf/dynamodb-admin) >/dev/null | ||
| echo "🔎 DynamoDB Admin is available at http://localhost:8001" | ||
|
|
||
| echo "✅ Done!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we set it up so that there's just one environment variable to set (like
USE_DYNAMODB=test), and when it's set like that then we set the others accordingly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this setup is possible: we will need to check the
USE_DYNAMODBvariable and, if it is set totest, construct theconfigaccordingly using thebuilder. Let me look into into it.