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

Fix Documentation: Document the default LogicalIds created by SAM

Open vikrambhatt opened this issue 9 years ago • 5 comments

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.

vikrambhatt avatar Jan 23 '17 18:01 vikrambhatt

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.

balldarrens avatar Mar 08 '17 15:03 balldarrens

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>Role is the execution role of function (AWS::IAM::Role resource type)
  • API Events:
    • ServerlessRestApi: LogicalID of the implicit AWS::ApiGateway::RestApi created by SAM.
    • ServerlessRestApiProdStage: AWS::ApiGateway::Stage resource created by SAM for API. If you happen to specify the RestApiId property of the event, replace Prod with stage name specified by the RestApi.
    • ServerlessRestApiDeployment<Sha-of-Swagger>: AWS::ApiGateway::Deployment resource 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::Permissions resource 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::Stage resource where is 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::Deployment resource 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.

sanathkr avatar Jun 28 '17 06:06 sanathkr

This issue seems to be a superset of #222.

rowanu avatar Dec 29 '17 21:12 rowanu

Duplicate of #251. Closing in favor of the Doc revamp. Also added "document generated LogicalIds" to that issue.

jfuss avatar Jan 10 '18 20:01 jfuss

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.

david-katz avatar Nov 19 '18 16:11 david-katz