csuermann / virtual-smart-home

Virtual Smart Home Skill for Amazon Alexa and Node-RED
27 stars 18 forks source link

How to upgrade my backend? #17

Closed thohoj closed 8 months ago

thohoj commented 9 months ago

Hi,

Amazon asks me to update to a newer nodejs version(16->20). I wanted to take this opportunity, to upgrade my vsh backend to the latest version. Currently I am on... I don't know. How can I determine the current version running? I think, the momento thing is definitely new....

Is there some documentation, how to upgrade an existing backend to the newest version?

BTW, is it ok to upgrade to nodejs 20?

Thank you for this great project!

csuermann commented 9 months ago

Hi @thohoj,

The repo is already updated to use Nodejs v20 and the README should cover the entire installation. You'll need to assess for yourself which steps you haven't executed yet.

Good luck!

thohoj commented 9 months ago

Then the right way is:

  1. discard all changes in my repo (if there are any...)
  2. pull main and sandbox branch
  3. do a complete new installation (readme...)

Do I have to delete some old stuff in my Amazon cloud?

csuermann commented 9 months ago

My guess is that you might only have to create a momento account and configure the respective environment variable. serverless deploy should then automagically update your AWS stack. You should not have to manually delete anything there.

thohoj commented 9 months ago

Now that I have a Momento account, I'm wondering what type of Momento token I need to create: API Key or Token? https://docs.momentohq.com/cache/develop/authentication

Also, I'm not sure which expiration date I should choose. Is this token only used for deployment or does it need a longer validity?

csuermann commented 9 months ago

It appears that Momento has altered the process for setting up API keys since my initial integration. Based on the current options, I recommend configuring it as follows:

image

Momento serves the purpose of caching the state of vsh devices to alleviate the need for frequent and expensive queries to users' Node-RED instances when Alexa requests device states. This optimization became crucial as VSH gained popularity, as the expenses associated with these queries were notable. For personal use, you might consider disabling caching, as it may not be necessary.

thohoj commented 9 months ago

Thank you for the detailed answer. I think disabling should be the way to go for me. I am using the backend for learning.

Is there already an option to disable caching?

Otherwise I would change the program sequence in UpdateState.ts so that readDevicePropsFromCache is not called and instead continue after // Cache miss! Would that be the right way?

csuermann commented 8 months ago

Unfortunately there is no built-in option to disable caching yet.

It might be easier to just short-circuit the functions

in cache.ts, e.g. based on a new environment variable.

thohoj commented 8 months ago

With short-circuit you mean... ...Throw exception in readDevicePropsFromCache() ...Return in writeDevicePropsToCache() and ...Return in deleteDevicePropsFromCache() ?

csuermann commented 8 months ago

Yes, exactly. Here is a PR that does it.

thohoj commented 8 months ago

I actually wanted to do it on my own, submit a PR and contribute something. I need to get faster and ask fewer questions 😄. Maybe next time. Thank you very much (again 👍)

I will report here how the update went. But it might take a while...

csuermann commented 8 months ago

Ahh, sorry for that. 😬

thohoj commented 8 months ago

Today I upgraded my backend. I reused most of the environment variables of the first install and unset the momento token variable. I checked each step for changed settings/urls/FunctionArn/...

I started serverless deploy from my raspberry pi, which was a bad idea. It's a 4GB an after 2000s it stalls. After I got the pi rebootet I restartet the whole procedure on my mac. 😒

I activated the "pro" plan as you described in the readme and configured node-red. I skipped step 3:

  1. Create a new vsh node and chose 'add new vsh-connection' from the connection dropdown because I had the old config node already in place.

In Step 4.:

  1. Replace the 'Backend URL' with the value you noted down in step 23, BUT WITHOUT THE trailing '/provision' !!! I didn't found the Backend URL field. Additionally the node reported an error:
    
    ERROR

fetching a fresh Access Token failed


Some virtual devices are working. Others reports `Device limit reached`.

Do I have to create a new config node instance? Or is there a workaround for this?

But I think I'm close to getting everything up and running again 😬
thohoj commented 8 months ago

I named the new DynamoDb attribute of TOKEN 'Plan' instead of 'plan' 🙄 The ERROR fetching a fresh Access Token failed stays but now all virtual devices are working again! I tried some switches and lights: all working well.

Thank you, great work 👍

csuermann commented 8 months ago

I started serverless deploy from my raspberry pi, which was a bad idea.

I recommend setting up GitHub Actions for deployment, like done in this repo.

I didn't found the Backend URL field

The field will only be shown after you have added vshConnectionShowSettings: true to your Node-RED settings.js and restarted Node-RED.

I named the new DynamoDb attribute of TOKEN 'Plan' instead of 'plan' 🙄

Actually, it should be "plan": "pro"