-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix: wrong cast of !Ref when using CommaDelimitedList #6768
Conversation
Good information from #4026 (comment)sam --version
SAM CLI, version 1.110.0 It's pretty easy to reproduce current issue. # Simple "sam init"
# Output: https://app.warp.dev/block/j5SwgAAQCg2bv9GN7uJAxP
> git clone [email protected]:EloB/aws-sam-cli-command.git
> cd aws-sam-cli-command/
> sam local start-api
Initializing the lambda functions containers.
Local image is up-to-date
Using local image: public.ecr.aws/lambda/nodejs:18-rapid-x86_64.
Mounting /Users/ollebroms/Documents/sam-app/hello-world as /var/task:ro,delegated, inside runtime container
Containers Initialization is done.
CORS Property AllowOrigins was not fully resolved. Will proceed as if the Property was not defined.
# ... Attempt 1, failed using parameters> sam local start-api --parameter-overrides CorsAllowedOrigins="https://www.google.com"
Initializing the lambda functions containers.
Local image is up-to-date
Using local image: public.ecr.aws/lambda/nodejs:18-rapid-x86_64.
Mounting /Users/ollebroms/Documents/sam-app/hello-world as /var/task:ro,delegated, inside runtime container
Containers Initialization is done.
CORS Property AllowOrigins was not fully resolved. Will proceed as if the Property was not defined.
# ... Attempt 2, failed using default value as stringGoto template.yaml file and uncomment > git apply <<EOF
diff --git a/template.yaml b/template.yaml
index aeaa32a..ea43120 100644
--- a/template.yaml
+++ b/template.yaml
@@ -9,7 +9,7 @@ Parameters:
CorsAllowedOrigins:
Type: CommaDelimitedList
# Uncomment the following to set the default value. Then rerun sam local start-api.
- # Default: "https://www.google.com"
+ Default: "https://www.google.com"
# Default: ["https://www.google.com"]
Description: The list of allowed origins for CORS
EOF
> sam local start-api
Initializing the lambda functions containers.
Local image is up-to-date
Using local image: public.ecr.aws/lambda/nodejs:18-rapid-x86_64.
Mounting /Users/ollebroms/Documents/sam-app/hello-world as /var/task:ro,delegated, inside runtime container
Containers Initialization is done.
CORS Property AllowOrigins was not fully resolved. Will proceed as if the Property was not defined.
# ... Attempt 3, works when providing default as array of stringsGoto template.yaml file and uncomment I think this indicates that > git checkout -- .
> git apply <<EOF
diff --git a/template.yaml b/template.yaml
index aeaa32a..af8d0b8 100644
--- a/template.yaml
+++ b/template.yaml
@@ -10,7 +10,7 @@ Parameters:
Type: CommaDelimitedList
# Uncomment the following to set the default value. Then rerun sam local start-api.
# Default: "https://www.google.com"
- # Default: ["https://www.google.com"]
+ Default: ["https://www.google.com"]
Description: The list of allowed origins for CORS
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
EOF
# Also build if you want to be able to fetch. Don't forget to remove folder between attempts.
> sam local start-api
Initializing the lambda functions containers.
Local image is up-to-date
Using local image: public.ecr.aws/lambda/nodejs:18-rapid-x86_64.
Mounting /Users/ollebroms/Documents/sam-app/hello-world as /var/task:ro,delegated, inside runtime container
Containers Initialization is done.
Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET, OPTIONS]
# ... |
Hi @EloB, thanks for your contributions and the detailed information 👍. We will try to validate the changes to make sure everything is working as expected. |
@@ -324,6 +324,9 @@ def get_translation(self, logical_id, resource_attributes=IntrinsicResolver.REF) | |||
if any(isinstance(logical_id_item, object_type) for object_type in [str, list, bool, int]): | |||
if resource_attributes not in (IntrinsicResolver.REF, ""): | |||
return None | |||
parameter_info = self._parameters.get(logical_id) | |||
if parameter_info and parameter_info.get("Type") == "CommaDelimitedList": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move the "CommaDelimitedList"
to a constant
@sidhujus @hnnasit I think it's better if you guys can help finalizing this issue. I don't have the experience to be able to write unit test and best practice syntax. The only knowledge I have in Python right now was to enable the debugger and step through the code than I let ChatGPT write the fix. If this was JavaScript or TypeScript. I would have no problem doing anything above. Best regards :) |
Would be good if this becomes merged because it fixes a bug/broken functionality. Right now it blocks local development if you have CORS functionality. Maybe you guys could add the test later on? |
Thank you for the contribution @EloB! |
Which issue(s) does this change fix?
#4026
Why is this change necessary?
When you pass a parameter with the type
CommaDelimitedList
and use it with!Ref
it should be transformed to an array of strings. Right now it's impossible to setAllowOrigins
in local development with!Ref
. You always get "CORS Property AllowOrigins was not fully resolved. Will proceed as if the Property was not defined." when usingsam local start-api
.https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html#parameters-section-structure-properties
How does it address the issue?
Resolves the correct type.
What side effects does this change have?
Don't know. First time I touched python. I'm happy that I got this far and fixed the issue. Review with care. Gladly take any feedback on how todo this the proper "python way". Best would probably if you guys take over this. 😅
I've tried this using
samdev local start-api
and was able to enable CORS using this fix.Mandatory Checklist
PRs will only be reviewed after checklist is complete
make pr
passesmake update-reproducible-reqs
if dependencies were changedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.