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

Api Path Can't Bet Set from Reference

Open BurgherJon opened this issue 6 years ago • 10 comments

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 "/"?

BurgherJon avatar Nov 29 '18 01:11 BurgherJon

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.

keetonian avatar Nov 30 '18 18:11 keetonian

Fn::Sub: is not supported either.

For example:

    ApiEvent:
      Type: Api
      Properties:
        Method: get
        Path:
          Fn::Sub: /${PathName}

ylynn avatar Feb 11 '19 18:02 ylynn

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.

whereisaaron avatar Aug 11 '19 06:08 whereisaaron

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?

1-fares avatar Feb 12 '21 08:02 1-fares

Documenting any exceptions like this in the CF reference would help prevent much wasted effort.

ggriffin avatar Feb 18 '21 18:02 ggriffin

Could really use this feature for API versioning, having to hard code version in path is a nightmare for our stacks with many resources.

RichDavis1 avatar Oct 07 '21 19:10 RichDavis1

this could really help in API versioning

sriharsha-samana avatar Nov 21 '21 14:11 sriharsha-samana

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.

mavwolverine avatar Jan 04 '22 04:01 mavwolverine

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!

mavwolverine avatar Jan 04 '22 04:01 mavwolverine

It's 2022, and this still forces me to hard code the path

LucienZhang avatar Mar 15 '22 07:03 LucienZhang

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

hoffa avatar Nov 03 '22 23:11 hoffa