1
votes

My goal is to check if a Cognito token is valid and not expired. I found this interesting and friendly package. https://www.npmjs.com/package/verify-cognito-token

I have already implemented it as an AWS lambda function, but for some reason I'm getting an error response.

//required params
const params = {
  region: '<your-aws-region>',
  userPoolId: '<your-user-pool-id>'
}

//optional claims examples
const claims = {
  aud: '<your-app-client-id>',
  email_verified: true,
  auth_time: time => time <= 1524588564,
  'cognito:groups': groups => groups.includes('Admins')
}

const Verifier = require('verify-cognito-token');
const verifier = new Verifier(params, claims);

verifier.verify(token)
.then(result =>{
  //result will be `true` if token is valid, non-expired, and has matching claims
  //result will be `false` if token is invalid, expired or fails the claims check
})

ERROR RESPONSE:

Response: { "errorMessage": "RequestId: 4f8d8756-c097-11e8-8adf-6f88f5e6d44a Process exited before completing request" }

Request ID: "4f8d8756-c097-11e8-8adf-6f88f5e6d44a"

Function Logs: START RequestId: 4f8d8756-c097-11e8-8adf-6f88f5e6d44a Version: $LATEST > 2018-09-25T07:47:54.317Z 4f8d8756-c097-11e8-8adf-6f88f5e6d44a /var/task/node_modules/verify-cognito-token/index.js:6 async function fetchKeys() { ^^^^^^^^ SyntaxError: Unexpected token function at createScript (vm.js:56:10) at Object.runInThisContext (vm.js:97:10) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at exports.handler (/var/task/index.js:17:22) END RequestId: 4f8d8756-c097-11e8-8adf-6f88f5e6d44a REPORT RequestId: 4f8d8756-c097-11e8-8adf-6f88f5e6d44a Duration: 191.85 ms Billed Duration: 200 ms Memory Size: 128 MB Max Memory Used: 19 MB
RequestId: 4f8d8756-c097-11e8-8adf-6f88f5e6d44a Process exited before completing request

1

1 Answers

3
votes

The problem was with Node 6.10.

The Lambda runtime environment should be set to Node 8.10 or higher to support async functions.