幸い、リンクした一連のCLIコマンドはCloudFormationで再現できResources
、サーバーレステンプレートのセクションにドロップできます。
この例では、GET
to/function1
はラムダ関数を呼び出し、GET
to/
は301を有名な検索エンジンに返します。
service: sls-301-mock
provider:
name: aws
runtime: nodejs12.x
stage: dev
region: us-east-1
functions:
hello:
handler: handler.hello
events:
- http:
path: function1
method: get
resources:
Resources:
Method:
Type: AWS::ApiGateway::Method
Properties:
HttpMethod: GET
ResourceId:
!GetAtt ApiGatewayRestApi.RootResourceId
RestApiId:
Ref: ApiGatewayRestApi
AuthorizationType: NONE
MethodResponses:
- ResponseModels: {"application/json":"Empty"}
StatusCode: 301
ResponseParameters:
"method.response.header.Location": true
Integration:
Type: MOCK
RequestTemplates:
"application/json": "{\n \"statusCode\": 301\n}"
IntegrationResponses:
- StatusCode: 301
ResponseParameters:
"method.response.header.Location": "'https://google.com'"
テスト済み:
Framework Core: 1.62.0
Plugin: 3.3.0
SDK: 2.3.0
Components Core: 1.1.2
Components CLI: 1.4.0
ノート
ApiGatewayRestApi
慣例により、イベントのためにサーバーレスによって作成されたAPI GatewayStageリソースの論理名ですhttp
。
関連するCloudFormationドキュメント
編集
この回答はそれほど冗長ではなくhttp
、Resources
セクションの代わりにイベントを使用します。私はそれをテストしていませんが、それはあなたのためにも働くかもしれません。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加