serverless-application-model icon indicating copy to clipboard operation
serverless-application-model copied to clipboard

FindInMap does not work in AllowOrigins (CorsConfiguration)

Open adrai opened this issue 5 years ago • 3 comments

Description: The new feature https://github.com/awslabs/serverless-application-model/pull/1381 (cors for http-api) does not resolve FindInMap

Steps to reproduce the issue: this works:

        "CorsConfiguration": {
          "AllowOrigins": [
            "http://localhost:3001"
          ],
          "AllowHeaders": [
            "Authorization",
            "Content-Type"
          ],
          "AllowMethods": [
            "GET",
            "HEAD",
            "PUT",
            "PATCH",
            "POST",
            "DELETE"
          ],
          "ExposeHeaders": [
            "X-Next-Page"
          ]
        }

this not:

"Mappings": {
    "EnvMap": {
      "dev": {
        "origins": [
          "http://localhost:3000"
        ]
      }
    }
  }
...
        "CorsConfiguration": {
          "AllowOrigins": {
            "Fn::FindInMap": [
              "EnvMap",
              {
                "Ref": "Environment"
              },
              "origins"
            ]
          },
          "AllowHeaders": [
            "Authorization",
            "Content-Type"
          ],
          "AllowMethods": [
            "GET",
            "HEAD",
            "PUT",
            "PATCH",
            "POST",
            "DELETE"
          ],
          "ExposeHeaders": [
            "X-Next-Page"
          ]
        }

adrai avatar Mar 13 '20 10:03 adrai

@adrai Thank you for reporting this! This will be fixed in #1529 PR

ShreyaGangishetty avatar Mar 23 '20 18:03 ShreyaGangishetty

I'm still having issues with this not working, I'd like to be able to control the AllowOrigins by environment by retrieving the list of origins from a mapping. It works fine for AllowMethods but not AllowOrigins.

Could you reopen the PR? Thanks.

chowson avatar Feb 18 '22 15:02 chowson

might as well call it AllowOrigin as it does not allow multiple origins

dannymoscoso avatar Mar 08 '22 08:03 dannymoscoso

You might be able to get this to work by adding AWS::LanguageExtensions to Transform as such:

Transform:
  - AWS::LanguageExtensions
  - AWS::Serverless-2016-10-31

AWS::LanguageExtensions resolves intrinsic functions if the value is known when Transforms are run.

See https://github.com/aws/serverless-application-model/issues/2533 for more information.

hoffa avatar Oct 17 '22 21:10 hoffa

Closing in favor of https://github.com/aws/serverless-application-model/issues/2533.

hoffa avatar Nov 03 '22 23:11 hoffa