-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ref to API Gateway RestApi from AWS::Serverless::Function Api Event Source #104
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. |
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. |
I have a similar issue, I got SAM to generate the API and wanting to call one of the Lambda functions to call into the API (in StateMachine). How Can the ServerlessRestApi be referred in AWS::Serverless::Function code? Still, the documentation is not clear |
If you define one or more functions that have an API event source that triggers that function and do not also define a gateway API that you then link to these functions by specifying This means that a template like this one will actually deploy a function behind an automatically created API gateway: AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: Lambda function behind an API gateway
Resources:
MyLambdaFunction: # you define this
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs14.x
CodeUri: lambda.zip
PackageType: Zip
Description: This lambda does something useful
Policies:
- AWSLambdaBasicExecutionRole
Events:
RootGet: # you define this
Type: Api
Properties:
Path: /
Method: GET
Outputs:
API:
Description: "API Gateway endpoint URL"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/${ServerlessRestApi.Stage}/" Given so much confusing information, it took me some time to figure all this out. |
Thanks for the comment. Issue is in defining the RestAPI within the same template. If Lambda is in the same template its not not get linked to the newly defined RestAPI |
What exactly are you trying to do? |
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:
How is one to access the API rest api, for example to output the url? Is there an example of this somewhere?
The text was updated successfully, but these errors were encountered: