Update - I have figured this out. Using ${ServerlessRestApi}, of which is not documented in a clear way, this is possible to build the URL. This is in an example provide in the examples folder. Just was not clear, or I was just foggy when reading that.
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Stage/"
I am wanting to output (Outputs) the underlying API Gateway RestApi from a AWS::Serverless::Function that is allowing this to be auto-generated. I have multiple AWS::Serverless::Function's in play, but as a short example:
Resources:
Create:
Type: AWS::Serverless::Function
Properties:
Handler: meta/create.create
CodeUri: app/
Runtime: nodejs4.3
Policies: AWSLambdaBasicExecutionRole
Environment:
Variables:
DYNAMODB_TABLE_ENV: !Sub '${ServiceName}-${Stage}'
Events:
ApiEventSource:
Type: Api
Properties:
Path: /
Method: POST
Delete:
Type: AWS::Serverless::Function
Properties:
Handler: meta/delete.delete
CodeUri: app/
Runtime: nodejs4.3
Policies: AWSLambdaBasicExecutionRole
Environment:
Variables:
DYNAMODB_TABLE_ENV: !Sub '${ServiceName}-${Stage}'
Events:
ApiEventSource:
Type: Api
Properties:
Path: /meta/{metaId}
Method: DELETE
How is one to access the API rest api, for example to output the url? Is there an example of this somewhere?
For my own future reference (when I find this issue again via Google in the future), here are the documentation references (I agree it's not laid out in a clear way):
ServerlessRestApi logical ID of the 'Implicit API' resource is documented in the 'internal' document "CloudFormation Resources Generated by SAM".https://[api-id].execute-api.[region].amazonaws.com/[stage] is documented at the top of "Set up Custom Domain Name for an API in API Gateway" in the API Gateway Developer Guide.It may be documented as described above, but not well enough to be functional.
this issue should be reopened.
Reopening to address improving documentation.
I think it's more than documentation. You get a circular reference trying to input the API URL into an environment variable.
@maletor I don't think you need to input the API URL into an environment variable, you get the API ID and anything else needed to create the URL from the event object.
Here's a sample API Event Object from the Lambda documentation: https://docs.aws.amazon.com/lambda/latest/dg/with-on-demand-https.html
@balldarrens @maletor did the documentation mentioned by @keetonian help with this issue? We are closing this issue due to inactivity, but please re-open of you are still having issues with this feature, in particular with the documentation.
Most helpful comment
For my own future reference (when I find this issue again via Google in the future), here are the documentation references (I agree it's not laid out in a clear way):
ServerlessRestApilogical ID of the 'Implicit API' resource is documented in the 'internal' document "CloudFormation Resources Generated by SAM".https://[api-id].execute-api.[region].amazonaws.com/[stage]is documented at the top of "Set up Custom Domain Name for an API in API Gateway" in the API Gateway Developer Guide.