serverless-application-model
serverless-application-model copied to clipboard
Api Path Can't Bet Set from Reference
I want to do a cloudformation deploy with an events section that looks like this and the parameter "ThePath is set to "/good":
Events:
Api2:
Type: Api
Properties:
Method: ANY
Path: !Ref ThePath
This results in:
Failed to create the changeset: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. Reason: Transform AWS::Serverless-2016-10-31 failed with: Internal transform failure.
When I modify the exact same file to use an actual path instead of a parameter it works fine:
Events:
Api2:
Type: Api
Properties:
Method: ANY
Path: /good
Perhaps the part of the code that is doing the validation won't let this happen because it can't verify that the parameter begins with a "/"?
CFN intrinsic functions are not currently supported in the "Path" parameter. This is because the path is necessary as a dictionary key in the generated swagger, and SAM can't resolve all CFN intrinsic functions.
We could potentially do this for template parameter values (as is done here), but I don't think we could do it for other values.
We would need to use the intrinsics resolver to resolve parameter values in where we handle and create events and verify that it works as expected.
Fn::Sub: is not supported either.
For example:
ApiEvent:
Type: Api
Properties:
Method: get
Path:
Fn::Sub: /${PathName}
I was trying to set the path from a parameter and sam validate just crashes out with this really not helpful error:
2019-08-11 01:44:36 Plugin 'ImplicitApiPlugin' raised an exception: unhashable type: 'dict'
Be nice to be able to resolve parameters here, or if not, to get a better validation error than that!
Thanks for the background @keetonian.
Note that this is an issue in other parts, in addition to the Api Path: basically everywhere that we may want to refer to resources outside of the current stack, differentiating between dev/staging/production.
Some examples are HttpApi's DomainName, CerficiateArn, Route53 HostedZoneId
@keetonian would you consider the above a valid feature request, and if so, would it need its own Guthub issue?
Documenting any exceptions like this in the CF reference would help prevent much wasted effort.
Could really use this feature for API versioning, having to hard code version in path is a nightmare for our stacks with many resources.
this could really help in API versioning
https://github.com/aws/serverless-application-model/blob/ce2744dfd912d14e431ceb58adab169c8d9849b5/samtranslator/plugins/api/implicit_rest_api_plugin.py#L83
this is the line that restricts it to be pure string.
Documenting any exceptions like this in the CF reference would help prevent much wasted effort.
spent almost half a day trying to investigate why it was failing! Open since 2018!
It's 2022, and this still forces me to hard code the path
Closing in favor of https://github.com/aws/serverless-application-model/issues/2533.