Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to customize allowed and cached HTTP methods for default behaviour #2502

Open
3 tasks done
domeq opened this issue Nov 8, 2022 · 1 comment
Open
3 tasks done

Comments

@domeq
Copy link

domeq commented Nov 8, 2022

Issue Summary

I'm trying to customize allowedHttpMethods and cachedHttpMethods properties of default caching behaviour.
Reason is I have people running a lot of POST requests on my frontpage bypassing any caching and causing a bill increase because of data transfer and lambda executions.

I'm following docs and setting:

inputs:
  cloudfront:
    defaults:
      allowedHttpMethods: [ 'GET', 'HEAD', 'OPTIONS' ]
      cachedHttpMethods: [ 'GET', 'HEAD', 'OPTIONS' ]

Actual behavior

Neither option works. No matter what value I pass the end result in the generated template in .serverless directory is always:

"defaults": {
    "minTTL": 0,
    "defaultTTL": 0,
    "maxTTL": 31536000,
    "allowedHttpMethods": [
      "HEAD",
      "DELETE",
      "POST",
      "GET",
      "OPTIONS",
      "PUT",
      "PATCH"
    ],
    "cachedHttpMethods": [
      "GET",
      "HEAD",
      "OPTIONS"
    ],
    "forward": {
      "headers": [
        "Host",
        "Authorization"
      ],
      "cookies": "all",
      "queryString": true
    },
    "queryString": false,
    "cookies": "none",
    "lambda@edge": {
      "origin-request": "xxx",
      "origin-response": "xxx"
    },
    "compress": true
  },

It's because both values are hardcoded and ignore any attempt of customization.

allowedHttpMethods is hardcoded here:

// everything after here cant be overridden
allowedHttpMethods: [
"HEAD",
"DELETE",
"POST",
"GET",
"OPTIONS",
"PUT",
"PATCH"
],

cachedHttpMethods is hardcoded here:

CachedMethods: {
Quantity: 2,
Items: ["HEAD", "GET"]
}

Is there any reason why are these options set the way they are and cannot be customized?

Expected behavior

Currently hardcoded values should rather be defaults that can be overwritten.

Versions

  • OS/Environment: Any
  • @sls-next/serverless-component version: 3.7.0
  • Next.js version: 11.1.2

Additional context

Checklist

  • You have reviewed the README and FAQs, which answers several common questions.
  • You have reviewed our DEBUGGING wiki and have tried your best to include complete information and reproduction steps (including your configuration) as is possible. As there is only one maintainer (who maintains this in his free time) and thus very limited resources, if you have time, please try to debug the issue a bit yourself if possible.
  • You have first tried using the most recent latest or alpha @sls-next/serverless-component release version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the old serverless-next.js component and the serverless-next.js plugin are deprecated and no longer maintained.
@Menahem1
Copy link

Hello,

Is there's still any workaround ?
I'm using websocket and need to add custom headers https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-working-with.websockets.html

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants