Deploying workers with serverless and environment variables

#1

All,

I’ve successfully deployed my first couple of version of my test JS Worker via the serverless framework. I’m now attempting to integrate with a third party server (send POST with a password) and I’ve set the password in serverless.yml under ‘environment’ . I’ve done this both for ‘functions’ and ‘provider’ without luck.

If I manually cut-n-paste the script into the workers sandbox, and add the environment variables as globals on the first two lines, e.g.

let DEV_URL = “https://dev.provider.com/endpoint
let PASSWORD = “abc123”

Then the script works as expected.

I’ve deliberately configured my git repo to ignore ‘.passwd.yml’, which contains these variables so that the secrets never get recorded into git.

I need to have my Workers honor and read the serverless environment variables. Has anyone figured out how to do that?

Thanks,

Jason.

#2

Bah. I’m seeing severe inconsistencies between the JS in my local repo and what gets actually deployed. More than just the webpack mangling. It seems serverless/webpack/CF is caching old versions somewhere (really old versions, like several hours). I’ve tried deleting .serverless/, node_modules/.cache, and dist/ and re-deploying without luck.

Time to remove variables. I found the workers configuration API https://developers.cloudflare.com/workers/api/ So I’m going with a straight makefile and a deploy.sh shell script. No caching. We’ll see if that removes the inconsistency. Additionally, it’ll allow me to programmatically prepend the secrets as global variables into a “built” JS script to be deployed by the shell script.

[edit] Also note that ‘sls deploy’ a) returns successfully, and b) reports no error messages. All cute green checks. So if the upload has been failing, it sure hasn’t mentioned it.