我是 AWS 无服务器世界和 SAM 的新手。我刚刚做了一个实际上功能齐全的小型机器人,但是当我开始做一个 SAM 模板来定义它时,我怀疑我无法弄清楚。我有一个 api 网关,它有一个特定的映射模板。我需要 sam 模板包含这个,但它没有,请检查模板:
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Serverless Specification template describing your function.
Resources:
certainty:
Type: 'AWS::Serverless::Function'
Properties:
Handler: index.handler
Runtime: nodejs8.10
CodeUri: ./certainty-function
Description: >-
This lambda monitors the ssl certificates expirations
and communite with slack.
MemorySize: 128
Timeout: 20
Role: 'arn:aws:iam::116738426468:role/ssl_cert_alerter'
Events:
Schedule1:
Type: Schedule
Properties:
Schedule: rate(1 day)
Api1:
Type: Api
Properties:
Path: /
Method: POST
certaintyassistant:
Type: 'AWS::Serverless::Function'
Properties:
Handler: index.handler
Runtime: nodejs8.10
CodeUri: ./certainty-assistant-function
Description: >-
This lambda invoke Certainty and answer to the slack
user.
MemorySize: 1152
Timeout: 300
Role: 'arn:aws:iam::116738426468:role/ssl_cert_alerter'
Events:
Api1:
Type: Api
Properties:
Path: /show-all
Method: POST
Environment:
Variables:
SLACK_TOKEN: oGprdUe0br93yH62fuezDHQh
所以说完这些,我想展示我如何管理 api 上的映射:
## designed just for post format.
{
#foreach( $token in $input.path('$').split('&') )
#set( $keyVal = $token.split('=') )
#set( $keyValSize = $keyVal.size() )
#if( $keyValSize >= 1 )
#set( $key = $util.urlDecode($keyVal[0]) )
#if( $keyValSize >= 2 )
#set( $val = $util.urlDecode($keyVal[1]) )
#else
#set( $val = '' )
#end
"$key": "$val"#if($foreach.hasNext),#end
#end
#end
}
我需要弄清楚如何为我的模板详细说明该映射,以便在更新 CloudFormation 上的堆栈时创建它。
也许如果我的方法不好,请告诉我应该怎么做。