https://github.com/veelenga/aws-dynamodb.cr
Crystal client for AWS DynamoDB
https://github.com/veelenga/aws-dynamodb.cr
Last synced: about 2 months ago
JSON representation
Crystal client for AWS DynamoDB
- Host: GitHub
- URL: https://github.com/veelenga/aws-dynamodb.cr
- Owner: veelenga
- License: mit
- Created: 2020-11-24T20:46:28.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2020-11-30T12:47:05.000Z (over 4 years ago)
- Last Synced: 2025-02-07T19:29:07.144Z (4 months ago)
- Language: Crystal
- Size: 35.2 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# aws-dynamodb
Crystal client for AWS DynamoDB.
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
aws-dynamodb:
github: veelenga/aws-dynamodb.cr
```2. Run `shards install`
## Usage
### Initialize client
```crystal
require "aws/dynamodb"client = Aws::DynamoDB::Client.new(
region: ENV["AWS_REGION"],
aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"],
aws_secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
endpoint: ENV["DYNAMODB_URL"]
)```
### Create table
``` crystal
client.create_table(
TableName: "Movies",
AttributeDefinitions: [
{
AttributeName: "Year",
AttributeType: "N"
},
{
AttributeName: "Name",
AttributeType: "S"
}
],
KeySchema: [
{
AttributeName: "Name",
KeyType: "HASH"
},
{
AttributeName: "Year",
KeyType: "RANGE"
}
],
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5
}
)```
### Put Item
``` crystal
client.put_item(
TableName: "Movies",
Item: {
Year: { N: 2008 },
Name: { S: "The Dark Knight" }
}
)```
### Get Item
```crystal
response = client.get_item(
TableName: "Movies",
Key: {
Year: { N: 2008 },
Name: { S: "The Dark Knight" }
}
)
response["Item"].try &.["Name"].s #=> "The Dark Knight"
```## Development
1. [Setting Up DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html).
Alternatively it can be running in a container:``` sh
$ docker pull amazon/dynamodb-local
$ docker run -p 8000:8000 amazon/dynamodb-local
```2. Pass credentials + DB URL and run the examples:
```sh
$ AWS_REGION=..\
AWS_ACCESS_KEY_ID=...\
AWS_SECRET_ACCESS_KEY=...\
DYNAMODB_URL=http://localhost:8000\
crystal examples/put_get_item.cr
```## Contributors
- [veelenga](https://github.com/veelenga) - creator and maintainer