04-18学习记录
利用CloudFormation创建了一个简单的模拟集成的serverless API接口。由于没有设置IAM权限,模板在生成时会自动创建新的角色。同时为了简化,也不需要配置任何的堆栈选项,模板配置如下:
Resources:
HelloWorldApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: HelloWorldApi
HelloWorldResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId: !GetAtt HelloWorldApi.RootResourceId
PathPart: HelloWorld
RestApiId: !Ref HelloWorldApi
HelloWorldMethod:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: "NONE"
HttpMethod: GET
Integration:
IntegrationHttpMethod: GET
Type: MOCK
RequestTemplates:
application/json: '{"statusCode": 200}'
IntegrationResponses:
-
ResponseTemplates:
application/json: '{"statusCode": 200,"message": "Hello World!"}'
StatusCode: 200
MethodResponses:
-
StatusCode: 200
ResourceId: !Ref HelloWorldResource
RestApiId: !Ref HelloWorldApi
对应的在资源里面就会显示已经创建好的资源,这时在控制台的界面就可以看到由模板生成的API Gateway了。
其实模板创建本质上和控制台没有什么区别,只是将控制台的操作变成自动化了,模板的配置和控制台里面的操作是完全可以对应上的,不过在模板里面需要各种Id将各个资源关联起来。