Skip to content

DynamoDB: Allow generation of custom values for hash and range key #201

Open
@robhughadams

Description

@robhughadams

I'd like to be able to use the plugin to support more complex request mapping scenarios for DynamoDB.

The shorthand mapping from querystring or path works really well for simple examples, but doesn't for more complex situations. E.g. where the hash and range key in the dynamo table are concatenated values and are exposed as separate parameters on the external API.

Ideally I'd be able to generate this request template:

"RequestTemplates": {
  "application/json": {
    "Fn::Sub": [
      "{\"TableName\": \"${TableName}\",\"Key\":{\"${HashKey}\": {\"${HashAttributeType}\": \"${HashAttributeValue}\"},\"${RangeKey}\": {\"${RangeAttributeType}\": \"${RangeAttributeValue}\"}}}",
      {
        "TableName": "some-table",
        "HashKey": "Foo_Bar",
        "HashAttributeType": "S",
        "HashAttributeValue": "${input.params().path.foo}_${input.params().querystring.bar}",
        "RangeKey": "Baz_Quux",
        "RangeAttributeType": "S",
        "RangeAttributeValue": "${input.params().path.baz}_${input.params().header.quux}"
      }
    ]
  }

using this serverless yaml:

hashKey:
  keyName: id
  attributeValue: \${input.params().path.foo}_\${input.params().querystring.bar}
  attributeType: S
rangeKey:
  keyName: range
  attributeValue: \${input.params().path.baz}_\${input.params().header.quux} # Custom mapping for the attribute. Use '\${}' to escape the '$' character.
  attributeType: S

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions