AWS::Serverless::Api和AWS::Serverless::HttpApi都是AWS CloudFormation模板中的资源类型,用于创建Serverless API网关和Lambda集成。它们的主要区别在于:
以下是AWS::Serverless::Api和AWS::Serverless::HttpApi的代码示例:
AWS::Serverless::Api示例:
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
MyFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: my-function/
Handler: index.handler
Events:
MyApiEvent:
Type: Api
Properties:
Path: /my-resource
Method: GET
RestApiId: !Ref MyApi
AWS::Serverless::HttpApi示例:
Resources:
MyHttpApi:
Type: AWS::Serverless::HttpApi
Properties:
Name: MyHttpApi
MyFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: my-function/
Handler: index.handler
Events:
MyHttpApiEvent:
Type: HttpApi
Properties:
Path: /my-resource
Method: GET
ApiId: !Ref MyHttpApi