aws-samples / aws-marketplace-serverless-saas-integration

Example of serverless integration for SaaS products listed on the AWS Marketplace.
MIT No Attribution
128 stars 76 forks source link

Empty entitleResponse object within the entitlement-sqs.js script #44

Closed bozhaobitsight closed 2 years ago

bozhaobitsight commented 2 years ago

Describe the bug Running into a runtime error on the entitlementService script with the following log: `2022-03-14T21:05:27.152Z 60da1f47-10a8-5a34-adc1-45eea0e044ea INFO entitlementsResponse {}

2022-03-14T21:05:27.152Z 60da1f47-10a8-5a34-adc1-45eea0e044ea ERROR Invoke Error
{ "errorType": "TypeError", "errorMessage": "Cannot read property '0' of undefined", "stack": [ "TypeError: Cannot read property '0' of undefined", " at /var/task/entitlement-sqs.js:33:67", " at runMicrotasks ()", " at processTicksAndRejections (internal/process/task_queues.js:97:5)", " at async Promise.all (index 0)", " at async Runtime.exports.handler (/var/task/entitlement-sqs.js:8:3)" ] }`

To Reproduce Steps to reproduce the behavior:

  1. Follow the AWS recommended quick start guide to deploy the stack
  2. Test creating a contract subscription
  3. The email to seller was never received, after investigation, determined that the entitlement-sqs.js is generating the fatal error with the log above, hence the record was never pushed onto the SNS queue.

Expected behavior This line in the entitlement-sqs.js, const entitlementsResponse = await marketplaceEntitlementService.getEntitlements(entitlementParams).promise(); should not be returning an empty object.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

chotafakir commented 2 years ago

The GetEntitlement call will receive a null response when there is no active subscription. If the subscription creation fails because of the customer's AWS account issue, then the entitlement will not be active. The customer on initial setup may reach the registration page before AWS Marketplace processes their subscription request. It is recommended to consider the Marketplace APIs as source of truth for verifying customer's subscription and provisioning access to your software. The serverless application is working as expected