aws-sam-cli
aws-sam-cli copied to clipboard
local start-api cannot accept path parameters including - (dash)
Describe your idea/feature/enhancement
I encountered the following error when I executed sam local start-api
> sam local start-api
Traceback (most recent call last):
File "/usr/local/bin/sam", line 33, in <module>
sys.exit(load_entry_point('aws-sam-cli==1.11.0', 'console_scripts', 'sam')())
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metrics.py", line 148, in wrapped
raise exception # pylint: disable=raising-bad-type
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metrics.py", line 114, in wrapped
return_value = func(*args, **kwargs)
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/samcli/commands/local/start_api/cli.py", line 72, in cli
do_cli(
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/samcli/commands/local/start_api/cli.py", line 148, in do_cli
service.start()
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/samcli/commands/local/lib/local_api_service.py", line 70, in start
service.create()
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/samcli/local/apigw/local_apigw_service.py", line 159, in create
self._app.add_url_rule(
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/flask/app.py", line 98, in wrapper_func
return f(self, *args, **kwargs)
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/flask/app.py", line 1278, in add_url_rule
self.url_map.add(rule)
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/werkzeug/routing.py", line 1482, in add
rule.bind(self)
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/werkzeug/routing.py", line 767, in bind
self.compile()
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/werkzeug/routing.py", line 836, in compile
_build_regex(self.rule if self.is_leaf else self.rule.rstrip("/"))
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/werkzeug/routing.py", line 803, in _build_regex
for converter, arguments, variable in parse_rule(rule):
File "/usr/local/Cellar/aws-sam-cli/1.11.0/libexec/lib/python3.8/site-packages/werkzeug/routing.py", line 228, in parse_rule
raise ValueError("malformed url rule: %r" % rule)
ValueError: malformed url rule: '/users/<something-name>/resources'
This is because I use /users/{something-name}/resources
as an API GW path parameter and Flask/werkzeung cannot accept path parameter names including -
.
# portion of SAM template
[snip]
SomethingManagerFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !FindInMap [ EnvironmentMap, !Ref Environment, SomethingManagerFunctionName]
CodeUri: .
Handler: something-manager
Role: !GetAtt SomethingManagerFunctionRole.Arn
Runtime: go1.x
Events:
ListSomethings:
Type: Api
Properties:
Path: /somethings
Method: GET
RestApiId:
Ref: SomethingApiGateway
ListUsersInSomething:
Type: Api
Properties:
Path: /users/{something-name}/resources
Method: GET
RestApiId:
Ref: SomethingApiGateway
[snip]
I could not notice that I cannot use path parameters except for /[a-zA-Z_][a-zA-Z0-9_]*/
until I read the code and documents of Flask and werkzeug. So, I want to clarify these implicit conventions for sam local start-api
.
Proposal
Fistly, I want to know if the behavior above is a bug or an intentional design for the sam local start-api
command.
Then I want to know how we can make the implicit rule clear. There are several options I can think of:
- Option1: Add document about the convention
- Option2: Validate conventions during path conversions
- Option3: Convert
-
to_
in during path convensions although it's tricky for users.
Additional Details
I plan to push PR based on the feedback from the maintainer of this repo but want to know which is the right direction for this project.
Any fix for this?
The team is aware of the request. We do not have an update to share at this time. However, we do tag PRs with issues they solve. Once the team prioritizes and solves it, you will be able to see that link in the issue
Once more vote +1 from me to solve this one.
I vote +1 to solve this one.
hey, any updates on it?