can u help me to integrate <https://www.npmjs.com/...
# help
a
can u help me to integrate https://www.npmjs.com/package/dynamodb-geo this package with stack to create table with this
f
Hi @ahmed elkordy, are you trying to use this package to create the table or access it?
a
Yeah
I wanna create table using framework
And using it inside. My function
f
I see. You’d have to create the table using SST instead of the npm. So if you can figure out what
createTableInput
is:
Copy code
const createTableInput = ddbGeo.GeoTableUtil.getCreateTableRequest(config);
You should be able to create the table using
Table
construct.
And you can use the code snippet in the README as is inside your functions.
a
Can u send me example for the sst code with this shema becouse i try it using typescript and get error
I log the shema but i can not convert it to sst
// Creating table with schema: const DataX = {   TableName: 'yourTableName',   ProvisionedThroughput: {     ReadCapacityUnits: 2,      WriteCapacityUnits: 5      },   KeySchema: [     { KeyType: 'HASH', AttributeName: 'hashKey' },     { KeyType: 'RANGE', AttributeName: 'rangeKey' }   ],   AttributeDefinitions: [     { AttributeName: 'hashKey', AttributeType: 'N' },     { AttributeName: 'rangeKey', AttributeType: 'S' },     { AttributeName: 'geohash', AttributeType: 'N' }   ],   LocalSecondaryIndexes: [     {       IndexName: 'geohash-index',       KeySchema: [         { KeyType: 'HASH', AttributeName: 'hashKey' },         { KeyType: 'RANGE', AttributeName: 'geohash' }       ],       Projection: { ProjectionType: 'ALL' }     }   ] }
@Frank??
s
@ahmed elkordy this section of the docs has what you need for creating the table: https://docs.serverless-stack.com/constructs/Table#configuring-an-index I worked toward the configuration by setting up this test in the sst stack, running
yarn test
and adding table props till it passed.
Copy code
import { expect, haveResource } from '@aws-cdk/assert';
import * as sst from '@serverless-stack/resources';
import MyStack from '../stacks/MyStack';

test('Test Stack', () => {
  const app = new <http://sst.App|sst.App>();
  // WHEN
  const stack = new MyStack(app, 'test-stack');
  // THEN
  expect(stack).to(
    haveResource('AWS::DynamoDB::Table', {
      TableName: 'yourTableName',
      ProvisionedThroughput: {
        ReadCapacityUnits: 2,
        WriteCapacityUnits: 5,
      },
      KeySchema: [
        { KeyType: 'HASH', AttributeName: 'hashKey' },
        { KeyType: 'RANGE', AttributeName: 'rangeKey' },
      ],
      AttributeDefinitions: [
        { AttributeName: 'hashKey', AttributeType: 'N' },
        { AttributeName: 'rangeKey', AttributeType: 'S' },
        { AttributeName: 'geohash', AttributeType: 'N' },
      ],
      LocalSecondaryIndexes: [
        {
          IndexName: 'geohash-index',
          KeySchema: [
            { KeyType: 'HASH', AttributeName: 'hashKey' },
            { KeyType: 'RANGE', AttributeName: 'geohash' },
          ],
          Projection: { ProjectionType: 'ALL' },
        },
      ],
    })
  );
});
a
Thanx alot @Simon Reilly
r
You should be able to pretty much copy the definition from the schema and change the case of the keys to suit the TypeScript types e.g.
Copy code
new sst.Table(this, 'myTable', {
      stream: dynamodb.StreamViewType.NEW_AND_OLD_IMAGES,
      fields: {
        PK: sst.TableFieldType.STRING,
        SK: sst.TableFieldType.STRING,
      },
      primaryIndex: { partitionKey: 'PK', sortKey: 'SK' },
      globalIndexes: {
        GSI1: {
          partitionKey: 'SK',
          sortKey: 'PK',
          indexProps: {
            projectionType: dynamodb.ProjectionType.ALL,
          },
        },
      },
...
a
@Ross Coundon thank u for help me
f
Thanks for chiming in guys @Simon Reilly @Ross Coundon!
Hey @ahmed elkordy, sorry I hit the bed after my last reply 😴 Were you able to get it to work?
a
@Frank No problem, I work on it today but it seem work