2018-9-14編集&追記
で1回試して失敗してまたやった。
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: samtest
Resources:
PostFunc:
Type: AWS::Serverless::Function
Properties:
Handler: samtesttest
Runtime: go1.x
CodeUri: s3://........
Role: arn:aws:iam::........
FunctionName: samtesttest
Timeout: 120
Environment:
Variables:
token: ........
Events:
PostResource:
Type: Api
Properties:
Path: /
Method: post
PostFuncLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${PostFunc}
RetentionInDays: 5
PostFuncApiGwMapping:
Type: AWS::ApiGateway::Method
Properties:
RestApiId:
Ref: ServerlessRestApi
ResourceId:
Fn::GetAtt:
- ServerlessRestApi
- RootResourceId
HttpMethod: POST
AuthorizationType: NONE
Integration:
Type: AWS
Uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${PostFunc.Arn}/invocations
IntegrationHttpMethod: POST
RequestTemplates:
application/x-www-form-urlencoded: "{\"body\": $input.json(\"$\")}"
これだと、Method already exists for this resource
でコケる。
が、
PostResource:
Type: Api
Properties:
Path: /samtesttest
Method: post
にすると、通るようにはなるが
apigatewayが
/
POST
/samtestest
POST
って感じにできてしまい、実際request templateの設定が入ってるのがルートのほうになる。
ResourceIdの指定あたりが何か匂うけど、俺はルートへのpost設定をなんとかしたいんだ。
何か余計な記述をしてるんだろうけど… 一応これはいけるまで、もしくは無理なことがわかるまでダラダラ追おう。
追記
上のは相当違った。
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: samtest
Resources:
PostFunc:
Type: AWS::Serverless::Function
Properties:
Handler: samtesttest
Runtime: go1.x
CodeUri: s3://........
Role: arn:aws:iam::........
FunctionName: samtesttest
Timeout: 120
Environment:
Variables:
token: ........
PostFuncLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${PostFunc}
RetentionInDays: 5
PostFuncAPI:
Type: AWS::Serverless::Api
Properties:
StageName: prod
DefinitionBody:
swagger: 2.0
info:
title: apigw_name
description: apigw_desc
version: "your api version"
schemes:
- https
paths:
/:
post:
consumes:
- application/x-www-form-urlencoded
produces:
- application/json
responses:
"200":
description: 200 response
schema:
$ref: "#/definitions/Empty"
x-amazon-apigateway-integration:
responses:
default:
statusCode: 200
uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${PostFunc.Arn}/invocations
passthroughBehavior: when_no_templates
httpMethod: POST
type: aws
contentHandling: CONVERT_TO_TEXT
requestTemplates:
application/x-www-form-urlencoded: "{\"body\": $input.json(\"$\")}"
definitions:
Empty:
type: object
title: Empty Schema
これが結構目的に近いことが出来た。
Stageリソース勝手に作ってたりするのがつらいが…
あとレスポンスのマッピングがされてないのも気になる。integrationのresponsesに明示してやらんとアカンか…?