Fix Documentation: Document the default LogicalIds created by SAM
SAM users were unable to figure out what ${ServerlessRestApi} referred to in this example: https://github.com/awslabs/serverless-application-model/blob/master/examples/2016-10-31/encryption_proxy/template.yaml
'ServerlessRestApi’ is the logicalId for the implicit API that gets created if you have the event type as API in your AWS::Serverless::Function, but it is not pointing to any API explicitly defined in the template.
This is not documented anywhere.
I agree. When there are multiple Functions, how do you reference them? What is the Ref or GetAttr structure on a Function that does not specifically the RestApiId (auto-generates the API? An example of that would be great.
Makes sense. We should expand this into a proper documentation file, but here is a start. You can !Ref or !GetAtt these resources. I understand you would be Referencing a resource that does not exist in the template. A better solution is to create SAM-specific intrinsics that will be resolved by SAM to appropriate resources. But until that happens, you can rely on the resource names:
AWS::Serverless::Function creates the following resources:
<function-logical-id>Roleis the execution role of function (AWS::IAM::Roleresource type)- API Events:
ServerlessRestApi: LogicalID of the implicitAWS::ApiGateway::RestApicreated by SAM.ServerlessRestApiProdStage:AWS::ApiGateway::Stageresource created by SAM for API. If you happen to specify theRestApiIdproperty of the event, replaceProdwith stage name specified by the RestApi.ServerlessRestApiDeployment<Sha-of-Swagger>:AWS::ApiGateway::Deploymentresource for implicit API. The swagger's SHA helps SAM to re-deploy the API every time you update the APIs<function-logical-id><api-name>Permission<stage-name>: Lambda permissions (AWS::Lambda::Permissionsresource type) required to give API Gateway access to invoke Lambda.is set to Prod for implicit APIs.
- Other events: TBD
AWS::Serverless::Api creates the following resources:
<api-logical-id>: AWS::ApiGateway::RestApi resource<api-logical-id><stage-name>Stage:AWS::ApiGateway::Stageresource whereis equal to the StageName property you specified. If you happened to use intrinsics here, SAM does not have access to resolve this. would be skipped in this case and become just <api-logical-id>Stage<api-logical-id>Deployment<Sha-of-Swagger>:AWS::ApiGateway::Deploymentresource for with first 10 characters of SHA of the swagger appended to allow automatic redeployment
AWS::Serverless::SimpleTable creates just a AWS::DynamoDB::Table resource with the same LogicalId
I will expand this with more examples add to the README.
This issue seems to be a superset of #222.
Duplicate of #251. Closing in favor of the Doc revamp. Also added "document generated LogicalIds" to that issue.
Note that the comments made here about the intrinsic names for Stage (and documented here: https://awslabs.github.io/serverless-application-model/internals/generated_resources.html#aws-serverless-api) appear to be wrong.
The "logicalId" for a Stage created by SAM now appears simply to be <API logical id>Stage (where logical id is just the name you gave the Serverless::API in your template. When I added in the stage name, I got an error that no such element exists and the stack deployment failed.