arc-plugin-tables-local-indexes

0.1.1 • Public • Published

Architect plugin: @tables-local-indexes

Defines Local Secondary Indexes for your project's DynamoDB tables. @tables-local-indexes should only ever be paired with @tables.

Recommended Resources

DynamoDB is a powerful database, though different from both SQL and NoSQL databases. It is highly recommended to dig into Amazon's resources to familiarize yourself with it:

Syntax

  • Note that local secondary indexes can only be declared at table creation: it cannot be changed afterwards; a new table would need to be created
  • @tables-local-indexes is a feature subset of @tables; as such, the names of your declared indexes must match those of your @tables
  • Otherwise, the basic syntax for defining @tables-local-indexes primary keys is similar to @tables:
    • Partition key - beware that local secondary indexes share the same partition key as the base table, so it can be skipped
    • Sort key, defined by **, is required
    • Currently only **String, and **Number are supported
  • An optional name property can be provided to explicitly name the index. This is helpful when querying the index with the AWS SDK as you know what to pass to the IndexName query parameter
  • An optional projection property can be provided to explicitly define which item attributes get projected, or included, in query results. By default, this plugin will project all item attributes (the ALL projection type as described in the DynamoDB documentation on attribute projections)
    • Customizing which attributes to project can be helpful when trying to save on bandwidth costs
    • Note that once a projection is defined, it cannot be changed; a new table would need to be created
    • Acceptable values for projection are:
      • all (default): all item attributes from the table are projected
      • keys: only the base table's partition key and the local secondary index' sort key are projected
      • Custom: otherwise, you may define one or more attribute names to explicitly project into the index. Note that the base table's partition key and index' sort key always get projected

Example

The following app.arc file defines a DynamoDB table with two Local Secondary Indexes, both with projection explicitly defined:

@app
testapp

@tables
accounts
  accountID *String

@tables-local-indexes
accounts
  email **String # Sort key is required!
  projection keys # only project base table's partition key and index' sort key (in this example that would be accountID and email)
  name byEmail

accounts
  accountID *String # Partition key is the same as the main table - it is optional, but explicitly declared here
  created **String # Sort key is required!
  projection updated lastAccessed # only project base table's partition key and index' sort key, plus the updated and lastAccessed attributes

Package Sidebar

Install

npm i arc-plugin-tables-local-indexes

Weekly Downloads

0

Version

0.1.1

License

Apache-2.0

Unpacked Size

20 kB

Total Files

5

Last publish

Collaborators

  • rafaelsacramento