question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG "The security token included in the request is invalid. (Service: DynamoDb, Status Code: 400, Request ID…"

See original GitHub issue

Describe the bug I am getting this error intermittently when loading data using graphql - the code is running a loop and seems to randomly fails with this error.

Amplify CLI Version 4:30.0

To Reproduce Not sure if this is reproducible

Expected behavior I wouldn’t expect random failure when processing data items in a loop.

Desktop (please complete the following information):

  • OS: macOS10.15.7
  • Node Version: v12.18.1

Additional context This seems to be a new issue that has started occurring

Sample Code

export const loadSessionTypeCodes = async () => {

  const results = await API.graphql({ query: customQueries.listSessionTypes });
  // console.log("results.data.listSessionTypes.items: " + results.data.listSessionTypes.items.length)
  console.log("listSessionTypes", results.data.listSessionTypes.items)

  if (results.data.listSessionTypes.items.length > 0) {
    return results.data.listSessionTypes.items.sort(function (a, b) { return a.name > b.name })
  }

  for (const item of sCodesInput) {
    console.log("item: " + item.name)
    try {
      const newCodeResult = await API.graphql({
        query: mutations.createSessionType, variables: {
          input: { name: item.name }
        }
      });

      const newCode = newCodeResult.data.createSessionType

      // Load activity types
      for (const subitem of item.activityTypes) {
        console.log("subitem: " + subitem.name)
        console.log("newSessionType.id: " + newCode.id)
        try {
          const newSubcode = await API.graphql({
            query: mutations.createActivityType, variables: {
              input: { name: subitem.name, activityTypeSessionTypeId: newCode.id }
            }
          });
        } catch (err) {
          console.log("error creating ActivityType codes", err)
        }

      }

      // Load modes
      for (const subitem of item.modes) {
        // console.log("subitem: " + subitem.name)
        // console.log("newSessionType.id: " + newCode.id)
        try {
          const newSubcode = await API.graphql({
            query: mutations.createMode, variables: {
              input: { name: subitem.name, modeSessionTypeId: newCode.id }
            }
          });
        } catch (err) {
          console.log("error creating Modes codes", err)
        }

      }

    } catch (err) {
      console.log("error creating SessionType codes", err)
    }

  }

  const listresults = await API.graphql({ query: customQueries.listSessionTypes });
  // console.log("listresults.data.listSessionTypes.items")
  // console.log(listresults.data.listSessionTypes.items)
  return listresults.data.listSessionTypes.items.sort(function (a, b) { return a.name > b.name })
}

** Additional information ** If I change the code to use graphqlOperation this error seems to go away - is there an explanation for this ?

export const loadSessionTypeCodes = async () => {

  const results = await API.graphql({ query: customQueries.listSessionTypes });
  // console.log("results.data.listSessionTypes.items: " + results.data.listSessionTypes.items.length)
  console.log("listSessionTypes", results.data.listSessionTypes.items)

  if (results.data.listSessionTypes.items.length > 0) {
    return results.data.listSessionTypes.items.sort(function (a, b) { return a.name > b.name })
  }

  for (const item of sCodesInput) {
    console.log("item: " + item.name)
    try {
      const newCodeResult = await API.graphql(graphqlOperation(mutations.createSessionType, {
          input: { name: item.name }
        }));

      const newCode = newCodeResult.data.createSessionType

      // Load activity types
      for (const subitem of item.activityTypes) {
        console.log("subitem: " + subitem.name)
        console.log("newSessionType.id: " + newCode.id)
        try {
          const newSubcode = await API.graphql(graphqlOperation(mutations.createActivityType, {
              input: { name: subitem.name, activityTypeSessionTypeId: newCode.id }
            }
          ));
        } catch (err) {
          console.log("error creating ActivityType codes", err)
        }

      }

      // Load modes
      for (const subitem of item.modes) {
        // console.log("subitem: " + subitem.name)
        // console.log("newSessionType.id: " + newCode.id)
        try {
          const newSubcode = await API.graphql(graphqlOperation(mutations.createMode, {
              input: { name: subitem.name, modeSessionTypeId: newCode.id }
            }
          ));
        } catch (err) {
          console.log("error creating Modes codes", err)
        }

      }

    } catch (err) {
      console.log("error creating SessionType codes", err)
    }

  }

  const listresults = await API.graphql({ query: customQueries.listSessionTypes });
  // console.log("listresults.data.listSessionTypes.items")
  // console.log(listresults.data.listSessionTypes.items)
  return listresults.data.listSessionTypes.items.sort(function (a, b) { return a.name > b.name })
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kaxaxcommented, Feb 22, 2021

For me issue started when I delete and recreate some table on amplify schema several times. after a few minutes issue disappeared on its own. I think appsync was trying to connect a new table with old (deleted same-named table) credentials. after few minutes it’s started to use new credentials and the issue disappeared. does anyone experience this issue for more than several minutes?

Amplify CLI Version 4.44.0

0reactions
github-actions[bot]commented, Feb 23, 2022

This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DynamoDB The security token included in the request is ...
I received this error when I had my region set to RegionEndpoint.APEast1 instead of RegionEndpoint.USEast1. My error, I accepted the first "East1" string...
Read more >
Amazon.DynamoDBv2.AmazonDynamoDBException ... - GitHub
I have the following error: Error Message: Amazon.DynamoDBv2.AmazonDynamoDBException : The security token included in the request is invalid. -- ...
Read more >
Resolve "The security token included in the request is expired ...
AmazonServiceException: The security token included in the request is expired (Service: AmazonSQS; Status Code: 403; Error Code: ExpiredToken; Request ID: ...
Read more >
The Security Token included in the Request is Invalid
The error "the Security Token included in the Request in Invalid" can occur for multiple reasons: ... The user's access key ID and...
Read more >
The security token included in the request is invalid. (Service ...
(Service: AmazonDynamoDBv2; Status Code: 400; Error Code: UnrecognizedClientException; Request ID: i_d) while testing Amazon Dynamo DB connection in IICS.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found