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.13k stars 738 forks source link

S3 delete persistent attributes not working #558

Closed harristom closed 5 years ago

harristom commented 5 years ago

I'm submitting a...


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

Expected Behavior

I set/save some persistent attributes, then delete them

Current Behavior

Could not delete item (x) from bucket (y): Access Denied

Steps to Reproduce (for bugs)

Skill is Alexa Hosted Skill and attributes are successfully saved after using instructions here.

Trying to delete with:

const attributesManager = handlerInput.attributesManager;
 await attributesManager.deletePersistentAttributes();

Results in the error above

Your Environment

"ask-sdk-core": "^2.0.7",
"ask-sdk-model": "^1.4.1",
"aws-sdk": "^2.326.0",
"ask-sdk-s3-persistence-adapter": "^2.0.0",

Alexa hosted skill

hideokamoto commented 5 years ago

The deleteAttributes() method is available in grater than 2.4.0. You should replace your package.json like this.

"ask-sdk-core": "^2.6.0",
"ask-sdk-model": "^1.16.0",
"aws-sdk": "^2.326.0",
"ask-sdk-s3-persistence-adapter": "^2.6.0",
harristom commented 5 years ago

Tried that but still getting the same error. The method definitely exists because the error I get is that I don't have access to the item in S3.

On Fri, 31 May 2019 at 01:36, Hidetaka Okamoto notifications@github.com wrote:

The deleteAttributes() method is available in grater than 2.4.0. You should replace your package.json like this.

"ask-sdk-core": "^2.6.0", "ask-sdk-model": "^1.16.0", "aws-sdk": "^2.326.0", "ask-sdk-s3-persistence-adapter": "^2.6.0",

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/issues/558?email_source=notifications&email_token=AMGXBDYL3RNVHHM32OOWUYTPYBQHZA5CNFSM4HRKCOKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWTZS2Q#issuecomment-497523050, or mute the thread https://github.com/notifications/unsubscribe-auth/AMGXBD56QYBGM4TKPOTKSV3PYBQHZANCNFSM4HRKCOKA .

hideokamoto commented 5 years ago

Well... Is the item not empty? Probably, some S3 API throws Access Denied error when the item not found in the S3 bucket.

Could you run the following code to reproduce the issue?

First test

The code will create an S3 object before deleting the object. So It will work well.

    const attributesManager = handlerInput.attributesManager;
    attributesManager.setPersistentAttributes({
      test: 'hello'
    })
    await attributesManager.savePersistentAttributes()
    await attributesManager.deletePersistentAttributes();

Second test

The example will throw an Error from getPersistentAttributes method. Because the user's S3 object is already deleted.

  const attributesManager = handlerInput.attributesManager;
  attributesManager.setPersistentAttributes({
      test: 'hello'
    })
  await attributesManager.savePersistentAttributes()
  await attributesManager.deletePersistentAttributes();
  try {
    const item =await attributesManager.getPersistentAttributes()
    console.log('Complete')
  } catch (e) {
   console.log(e)
   console.log('actual')
  } 

I think

We should use try ~ catch to run the deletePersistentAttributes() method. Because sometime the S3 object is not found.

  try {
    await attributesManager.deletePersistentAttributes()
  } catch (e) {
   console.log(e)
  } 
franklin-lobb commented 5 years ago

I tried this and found the function through the error when using Hosted Skills, and did not throw an error if the function was running in my own AWS account.

hideokamoto commented 5 years ago

How do you create the adaptor? In Hosted skill, we need to set the process.env.S3_PERSISTENCE_BUCKET param to bucketName.

Alexa.SkillBuilders.custom()
  .withPersistenceAdapter(
    new persistenceAdapter.S3PersistenceAdapter({
       bucketName: process.env.S3_PERSISTENCE_BUCKET
    })
  )
franklin-lobb commented 5 years ago

Within the Alexa-hosted environment, you set bucketName to the S3_PERSISTENCE_BUCKET value which is set by the Alexa-hosted environment to your S3 bucket name. To create the adapter outside of the Alexa-hosted environment, set bucketName to the name of the bucket you want to store the data in (ensuring the function execution role has appropriate access to the bucket).

ShenChen93 commented 5 years ago

Hi @harristom @franklin-lobb ,

Thanks for reporting this bug. I reproduced the error you mentioned, but it's not our sdk side problem. Therefore, I need to reach out to host skill team to figure it out. Will inform you once I got their response.

Thanks, Shen

ShenChen93 commented 5 years ago

The service team started their work on this issue. Will update here once they fixed it.

ShenChen93 commented 5 years ago

@harristom @franklin-lobb

I think this issue has been fixed already. Could you please try and see if the problem still exist ?

Thanks, Shen

ShenChen93 commented 5 years ago

Close it for now, please feel free to reopen it if the problem still exist.