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

ExpiredTokenException when it comes to mocking DynamoDB #250

Open
FaresKi opened this issue Nov 4, 2021 · 0 comments
Open

ExpiredTokenException when it comes to mocking DynamoDB #250

FaresKi opened this issue Nov 4, 2021 · 0 comments

Comments

@FaresKi
Copy link

FaresKi commented Nov 4, 2021

Hi!
I'm starting to test my lambda using this package and am facing this ExpiredTokenException because I feel like I'm not correctly mocking my DynamoDB.
My lambda is pretty straightforward :

//lambda.ts
export const handler: APIGatewayProxyHandlerV2 = async (event: any) => {
  const body = JSON.parse(event.body)
  await doStuff(body);
}

//doStuff.ts
export const readItem = async function (
  id: body.id
  tableName: string,
  consistentRead: boolean = false
) {
  const response = await ddbDocumentClient.send(
    new GetCommand({
      TableName: tableName,
      Key: {
        id: id,
      },
      ConsistentRead: consistentRead,
    })
  )

  return response.Item as Item
}

My lambda test is similar to this :

...
AWSMock.mock("DynamoDB", "getItem", (params: PutItemInput, callback: Function) => {
      console.log("DynamoDB", "getItem", "mock called")
      callback(null, {})
    })
...

Am I doing this correctly?

Thanks in advance.

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

1 participant