dxdc / aws-sdk-google-apps

Native Google Apps Script support for Amazon AWS SDK for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getRandomValues issue

craigedmunds opened this issue · comments

I've rebuilt the sdk to add athena, pushed it up to google with clasp & am referencing it from my script - all seemingly hunky dory.

But when I attempt to use the athena SDK I get an error "Error: crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported"

I can see how this is generated looking at the un-minimised code on my machine.

I can also see it in the minimal code in https://github.com/dxdc/aws-sdk-google-apps/blob/master/dist/AwsSdk.js

(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=function(){if(!getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return getRandomValues(rnds8)};var getRandomValues="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),rnds8=new Uint8Array(16)},{}],120:[function(require,module,exports){"use strict";function f(s,x,y,z){switch(s){case 0:return x&y^~x&z;case 1:return x^y^z;case 2:return x&y^x&z^y&z;case 3:return x^y^z}}function ROTL(x,n){return x<<n|x>>>32-n}Object.defineProperty(exports,

But the error doesn't seem to happen when I use the original script referenced in your README.

Digging a bit further, startQueryExecution errors, but not methods like listDataCatalogs. I'm guessing this is because startQueryExecution generates a uuid to track the async query.

Looking at the definition for the method i wonder if its related to idempotency:true / idempotencyToken?...

"StartQueryExecution": {
      "input": {
        "type": "structure",
        "required": [
          "QueryString"
        ],
        "members": {
          "QueryString": {},
          "ClientRequestToken": {
            "idempotencyToken": true
          },
          "QueryExecutionContext": {
            "shape": "S14"
          },
          "ResultConfiguration": {
            "shape": "Sw"
          },
          "WorkGroup": {},
          "ExecutionParameters": {
            "shape": "S1f"
          }
        }
      },
      "output": {
        "type": "structure",
        "members": {
          "QueryExecutionId": {}
        }
      },
      "idempotent": true
    },

I think there is some issue with your aws sdk clone. Maybe you forgot to run npm install in that folder? I rebuilt it for you here using:

sdk = ses,s3,lambda,ec2,athena

Easy enough to try and see if it's working for you now:

AwsSdk.js.zip

I don’t think that’s it no - many of the methods work, just not StartQueryExecution

I have worked around it by passing in a parameter called ClientRequestToken, which avoids it trying to create one itself

OK, I'm not sure. It's possible some additional patching or polyfills may be required.

@craigedmunds please test the latest version against your use case.

I created a polyfill for getRandomValues (part of the Web Crypto API), and tested it against the UUID library in the GAS environment. This polyfill isn't cryptographically secure, but I'm not sure there is a convenient way to achieve that in GAS.

closing for now, please re-open/comment if you have an update, thanks!