Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I create this sst dynamo DB resource #138

Open
IdrisExclusive opened this issue Jan 7, 2025 · 3 comments
Open

How can I create this sst dynamo DB resource #138

IdrisExclusive opened this issue Jan 7, 2025 · 3 comments

Comments

@IdrisExclusive
Copy link

IdrisExclusive commented Jan 7, 2025

table: Resource.LambdaAuthTable.name,

There is no reference on how to create the dynamo DB resource for auth in the example code or on the sst page. What is the table structure?

@mwood23
Copy link

mwood23 commented Jan 7, 2025

If you are using SST you need to create this yourself:

const authTable = new sst.aws.Dynamo('LambdaAuthTable', {
  fields: {
    pk: 'string',
    sk: 'string',
  },
  ttl: 'expiry',
  primaryIndex: {
    hashKey: 'pk',
    rangeKey: 'sk',
  },
});

And then link it to your auth handler:

const auth = new sst.aws.Function('MyAuth', {
  handler: 'packages/app-backend/src/auth.handler',
  link: [authTable],
});

@Belfio
Copy link

Belfio commented Jan 8, 2025

This is what I added to my stack and is working

/// <reference path="../.sst/platform/config.d.ts" />

const AuthStack = () => {
  const authTable = new sst.aws.Dynamo("AuthTable", {
    fields: {
      pk: "string",
      sk: "string",
    },
    ttl: "expiry",
    primaryIndex: {
      hashKey: "pk",
      rangeKey: "sk",
    },
  });

  const auth = new sst.aws.Auth("Auth", {
    authorizer: {
      handler: "backend/auth/authorizer.handler",
      link: [authTable],
    },
  });
  return {
    auth,
  };
};

export default AuthStack;

@bchilcott
Copy link

If you're using the Auth construct you don't even have to define the DynamoDB yourself:

const auth = new sst.aws.Auth('Auth', {
  authorizer: {
    handler: 'packages/app-backend/src/auth.handler',
  },
});

And then you don't have to specify storage it in your issuer - the details are passed to it through an environment variable and picked up by the issuer automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants