Serverless-application-model: Ref to API Gateway RestApi from AWS::Serverless::Function Api Event Source

Created on 8 Mar 2017  路  6Comments  路  Source: aws/serverless-application-model

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?

areserverless-api typdocumentation

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):

All 6 comments

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):

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.

Was this page helpful?
0 / 5 - 0 ratings