alexa / alexa-skills-kit-sdk-for-nodejs

The Alexa Skills Kit SDK for Node.js helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Apache License 2.0
3.12k stars 736 forks source link

AskSdk.DynamoDbPersistenceAdapter Error: Could not read item #714

Open leandrock opened 2 years ago

leandrock commented 2 years ago

I'm submitting a...


[ X ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Other... Please describe:

Expected Behavior

Current Behavior

Creating a new skill and using the code I allways use on other skills and cannot make the session attributes persist on dynamodb.

Relevant snippets from index.js:

const {DynamoDbPersistenceAdapter} = require('ask-sdk-dynamodb-persistence-adapter');
const { strict } = require('assert');
const persistenceAdapter = new DynamoDbPersistenceAdapter({ 
    tableName: 'table_name',
    createTable: true,
});
const LaunchRequestHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
    },
    async handle(handlerInput) {
        const attributes = await persistenceAdapter.getAttributes(handlerInput.requestEnvelope);
        const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
...
        handlerInput.attributesManager.setSessionAttributes(sessionAttributes);
}

exports.handler = Alexa.SkillBuilders.custom()
    .addRequestHandlers(
        LaunchRequestHandler,
        CancelAndStopIntentHandler,
        SessionEndedRequestHandler,
        FallbackIntentHandler
    )
    .withPersistenceAdapter(persistenceAdapter)
    .addErrorHandlers(
        ErrorHandler,
    )
    .lambda();

Cloudwatch logs:

2022-04-11T14:20:07.845Z    03d7758b-fb01-4d7e-be9c-6bb921f340c7    INFO    ~~~~ Error handled: AskSdk.DynamoDbPersistenceAdapter Error: Could not read item (amzn1.ask.account.AG2OPN...) from table (table_name): There were 227 validation errors:
* InvalidParameterType: Expected params.Key['id'] to be a structure
* UnexpectedParameter: Unexpected key '0' found in params.Key['id']
* UnexpectedParameter: Unexpected key '1' found in params.Key['id']
...
* UnexpectedParameter: Unexpected key '223' found in params.Key['id']
* UnexpectedParameter: Unexpected key '224' found in params.Key['id']
* InvalidParameterType: Expected params.getByIndex to be a string
    at Object.createAskSdkError (/var/task/node_modules/ask-sdk-runtime/dist/util/AskSdkUtils.js:22:17)
    at DynamoDbPersistenceAdapter.<anonymous> (/var/task/node_modules/ask-sdk-dynamodb-persistence-adapter/dist/attributes/persistence/DynamoDbPersistenceAdapter.js:123:46)
    at step (/var/task/node_modules/ask-sdk-dynamodb-persistence-adapter/dist/attributes/persistence/DynamoDbPersistenceAdapter.js:45:23)
    at Object.throw (/var/task/node_modules/ask-sdk-dynamodb-persistence-adapter/dist/attributes/persistence/DynamoDbPersistenceAdapter.js:26:53)
    at rejected (/var/task/node_modules/ask-sdk-dynamodb-persistence-adapter/dist/attributes/persistence/DynamoDbPersistenceAdapter.js:18:65)

Possible Solution

Steps to Reproduce (for bugs)

Context

Your Environment

Node.js and NPM Info

rahulawl commented 2 years ago

Is this issue/feature-request still relevant? We are working on prioritization of relevant issues and cleanup of rest. If we don’t hear back in 2 weeks, we will assume that the issue is not relevant and we will close it.

jefforulez commented 1 year ago

@leandrock did you use a newer version of the AWS SDK?

i just ran into and posted this issue: https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/issues/726