cloudcomponents / cdk-constructs

A collection of higher-level reusable cdk constructs
MIT License
625 stars 104 forks source link

[cdk-contentful-webhook]: Custom Resource "serviceToken" and "logLevel" are being sent to Contentful API #147

Closed iDVB closed 2 years ago

iDVB commented 2 years ago

Getting the error The body you sent contains an unknown key. When you inspect the body you can see that the custom resource seems to be sending the service token as well?

Payload

{
  "serviceToken": "arn:aws:lambda:us-east-1:NOTTELLING:function:nottelling-CustomContentfulWebhook91f2075fb950474-7EnJW7VrCDNK",
  "topics": [
    "*.*"
  ],
  "url": "https://nottelling.execute-api.us-east-1.amazonaws.com/webhook-algolia",
  "logLevel": "debug",
  "name": "Algolia Create/Update",
  "headers": []
}

CloudFormation Error

CREATE_FAILED | Custom::ContentfulWebhook | ContentfulAppContentfulWebhookCustomResource5806A09B | Received response status [FAILED] from custom resource. Message returned: {
  "status": 400,
  "statusText": "Bad Request",
  "message": "The body you sent contains an unknown key.",
  "details": {
    "errors": [
      {
        "keys": [
          "service_token",
          "log_level"
        ]
      }
    ]
  },
  "request": {
    "url": "webhook_definitions",
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Content-Type": "application/vnd.contentful.management.v1+json",
      "X-Contentful-User-Agent": "sdk contentful-management.js/6.3.2; platform node.js/v12.22.7; os Linux/4.14.252-207.481.amzn2.x86_64;",
      "Authorization": "Bearer ...A5iUk",
      "user-agent": "node.js/v12.22.7",
      "Accept-Encoding": "gzip",
      "Content-Length": 288
    },
    "method": "post",
    "payloadData": "{\"serviceToken\":\"arn:aws:lambda:us-east-1:NOTTELLING:function:nottelling-CustomContentfulWebhook91f2075fb950474-7EnJW7VrCDNK\",\"topics\":[\"*.*\"],\"url\":\"https://nottelling.execute-api.us-east-1.amazonaws.com/webhook-algolia\",\"logLevel\":\"debug\",\"name\":\"Algolia Create/Update\",\"headers\":[]}"
  },
} 

I tried to contrib a PR but I'm not sure how the development workflow works. When I create yarn links to the package root I end up getting Circular dependency issues.

It appears though that we just need to destructure out serviceToken and logLevel for this to work.

Example:

  const { accessTokenString, spaceId, serviceToken, logLevel, ...props } = camelizeKeys<WebhookProps, CloudFormationCustomResourceEventCommon['ResourceProperties']>(
    event.ResourceProperties,
  );

If someone can point me in the right direction on what the dev workflow is to test this using yarn link I'd be happy to submit a PR.

hupe1980 commented 2 years ago

The example is linked. You can use it to test your change: https://github.com/cloudcomponents/cdk-constructs/tree/master/examples/contentful-webhook-example

iDVB commented 2 years ago

thanks @hupe1980 Was hoping there was more info on how to yarn link this module into our project to see it work. Also steps for linting, building etc. eg. Build all modules with lerna or only the one.