evolv-ai / serverless-offline-edge-lambda

A plugin for the Serverless Framework that simulates the behavior of AWS CloudFront Edge Lambdas while developing offline
Other
13 stars 11 forks source link

Support for custom headers #157

Closed joquijada closed 1 year ago

joquijada commented 3 years ago

I have a Lambda@Edge associated with a resource of type AWS::CloudFront::Distribution. This cloud distribution configures a few custom headers that are part of every event sent through to the Lambda@Edge. This plugin seems to be ignoring those custom headers. Can this be supported? Below are relevant snippets from my serverless.yml:

functions:
  MyLambdaFunc:
    name: 'my-handkler-${self:provider.stage}'
    handler: my-handkler.originRequest"
    memorySize: 256
    timeout: 20
    lambdaAtEdge:
      distribution: 'CloudFrontDistribution'
      eventType: 'origin-request'

...

resources:
  Resources:
    CloudFrontDistribution:
      Type: AWS::CloudFront::Distribution
      Properties:
        DistributionConfig:
          Enabled: true
          DefaultCacheBehavior:
            TargetOriginId: 'S3-blah'
            ViewerProtocolPolicy: 'allow-all'
            CachePolicyId:
              Fn::GetAtt: ['CloudFrontCachePolicy', 'Id']
            Compress: false
            ForwardedValues:
              QueryString: false
              Cookies:
                Forward: 'none'
          Origins:
            - DomainName: "blah.s3.amazonaws.com"
              OriginCustomHeaders:
                - HeaderName: 'header-one-name'
                  HeaderValue: 'header-one-val'
                - HeaderName: 'header-two-name'
                  HeaderValue: 'header-two-val'
...

Notice the OriginCustomHeaders: that should be part of every request event. AWS puts the custom headers in the request JSON as follows,

{
  Records: [
    {
      cf: {
        request: {
          origin: {
            s3: {
              customHeaders: {
                'header-one-name': [{ header-one-val' }],
                'header-two-name': [{ value: 'header-two-val' }]
              }
            }
          },
          headers: {
            ...
          }
        },
        response: {
          headers: {}
        }
      }
    }
  ]
}
mattstrom commented 1 year ago

Should be addressed by #261