Amazon web services 如何使用CloudFormation创建每隔几分钟调用网关API的规则?
我正试图在CloudFormation中创建一个CloudWatch规则,每隔几分钟触发一个网关API,但我很难找到有关如何填充模板某些部分的文档 例如,这是我们在CF模板中的内容:Amazon web services 如何使用CloudFormation创建每隔几分钟调用网关API的规则?,amazon-web-services,aws-lambda,amazon-cloudformation,aws-sam,Amazon Web Services,Aws Lambda,Amazon Cloudformation,Aws Sam,我正试图在CloudFormation中创建一个CloudWatch规则,每隔几分钟触发一个网关API,但我很难找到有关如何填充模板某些部分的文档 例如,这是我们在CF模板中的内容: SomeAPI: Type: AWS::Serverless::Function Properties: Handler: api Runtime: go1.x CodeUri: ../../deploy/bla.zip Timeout: 600
SomeAPI:
Type: AWS::Serverless::Function
Properties:
Handler: api
Runtime: go1.x
CodeUri: ../../deploy/bla.zip
Timeout: 600
VpcConfig:
SecurityGroupIds:
- !ImportValue VPCSecurityGroup
SubnetIds:
- !ImportValue PrivateSubnetA
- !ImportValue PrivateSubnetB
Events:
TestApiPing:
Type: Api
Properties:
Path: /test-api/ping
Method: GET
我想让CF创建一个调用ping API的规则,但在填写目标部分时遇到困难:
TestRule:
Type: AWS::Events::Rule
Properties:
Name: "test-ping-rule"
ScheduleExpression: "cron(0/15 * ? * * *)"
Targets:
-
Arn:
Fn::GetAtt:
- "PingFunction"
- <what to put here?>
Id: "TargetFunctionV1"
TestRule:
类型:AWS::Events::Rule
特性:
名称:“测试ping规则”
ScheduleExpression:“cron(0/15*?***)”
目标:
-
Arn:
Fn::GetAtt:
-“PingFunction”
-
Id:“TargetFunctionV1”
谢谢你的帮助 经过今天的反复试验,我终于找到了解决办法。在无服务器函数定义的事件部分下,可以执行以下操作:
Events:
PublicApi:
Type: Schedule
Properties:
Schedule: cron(0/5 * ? * * *)
Input: '{ "httpMethod": "GET", "path": "/public_api/ping" }'
为什么要安排API网关调用而不是安排Lambda函数执行?我不必这样做,但我们的Lambda函数是使用AWS::Serverless::function这样定义的。我不知道如何以这种方式引用Lambda函数。