aws-dynamodb

AWS DynamoDB API bindings for NoSQL database operations.

Usage

::dynamodb ::aws::dynamodb

// Put an item
::dynamodb/put-item("my-table", {id: {S: "123"}, name: {S: "Alice"}})

// Get an item
item ::dynamodb/get-item("my-table", {id: {S: "123"}})

// Query items
results ::dynamodb/query("my-table", "id = :id", {":id": {S: "123"}})

// Scan table
all-items ::dynamodb/scan("my-table")

Per-call credentials

Pass opts as the last argument of any function to use other credentials for that call, so one run can serve many tenants. Nothing is written to context, so this is safe in parallel flows.

A per-call credential is masked in the run's call records, including inside strings like Bearer ${key}. A secret shorter than 8 bytes is masked only as a whole value. Records of your own calls that finished before this one may already be written, so mark a credential your code fetches with ::hot::ctx/mark-secret as soon as you have it.

::dynamodb ::aws::dynamodb

opts {
    access-key-id: "AKIAEXAMPLE",
    secret-access-key: "tenant-secret",
    session-token: "optional-for-temporary-credentials",
    region: "eu-west-1"
}

::dynamodb/get-item("my-table", {pk: {S: "user-1"}}, opts)
::dynamodb/query("my-table", "pk = :pk", {":pk": {S: "user-1"}}, opts)

opts also takes credentials (a ready ::aws::core/Credentials value) and endpoint (a base URL such as LocalStack). Without credentials in opts, the aws.* context variables are used. These are errors, returned before anything is sent:

  • access-key-id, secret-access-key or credentials in opts but null or blank (leave it out instead); a null or blank session-token just means no session token
  • half a key pair
  • an endpoint in opts without credentials in opts

Where a function's last parameter is already a Map, opts comes after it, and a shorter form without that Map isn't offered: pass {} or null for it.

Required IAM Permissions

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "DynamoDBTableAccess",
            "Effect": "Allow",
            "Action": [
                "dynamodb:PutItem",
                "dynamodb:GetItem",
                "dynamodb:DeleteItem",
                "dynamodb:UpdateItem",
                "dynamodb:Query",
                "dynamodb:Scan",
                "dynamodb:BatchGetItem",
                "dynamodb:BatchWriteItem",
                "dynamodb:DescribeTable"
            ],
            "Resource": [
                "arn:aws:dynamodb:<REGION>:<ACCOUNT_ID>:table/<TABLE_NAME>",
                "arn:aws:dynamodb:<REGION>:<ACCOUNT_ID>:table/<TABLE_NAME>/index/*"
            ]
        },
        {
            "Sid": "DynamoDBListTables",
            "Effect": "Allow",
            "Action": [
                "dynamodb:ListTables"
            ],
            "Resource": "*"
        }
    ]
}

Replace <REGION>, <ACCOUNT_ID>, and <TABLE_NAME> with your values.

Documentation

Full documentation available at hot.dev/pkg/aws-dynamodb

License

Apache-2.0 - see LICENSE