如何使用 CloudWatch 规则触发部署 StepFunciton?
无服务器工具有无服务器步骤功能插件,但尚不支持 CloudWatch 事件。
如果可以通过 CloudFormation 部署这样的管道,您能否提供一些示例 CF 模板和 bash 命令。
如何使用 CloudWatch 规则触发部署 StepFunciton?
无服务器工具有无服务器步骤功能插件,但尚不支持 CloudWatch 事件。
如果可以通过 CloudFormation 部署这样的管道,您能否提供一些示例 CF 模板和 bash 命令。
听起来您在询问使用 Lambda 构建状态机的 Cloudformation 模板。
AWS Step Functions 支持 Cloudformation 模板、Cloudwatch 事件触发器和 API 网关(如果需要)。
AWS 文档中有一个很好的教程,可以按照在 Cloudformation 中设置您的状态机。你可以在这里找到:http: //docs.aws.amazon.com/step-functions/latest/dg/tutorial-lambda-state-machine-cloudformation.html
对于 bash 命令,您可以使用 AWS CLI 创建、删除和部署您的堆栈。以下是对文档的参考:http: //docs.aws.amazon.com/cli/latest/reference/cloudformation/index.html。
可以在此处找到如何将 CLI 与 Cloudformation 一起使用的示例:http: //docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-using-cli.html。
对于启动和停止执行,可以在此处找到 AWS Step Functions CLI 文档:http: //docs.aws.amazon.com/cli/latest/reference/stepfunctions/index.html。
希望这可以帮助!
我遇到了类似的问题,但在无服务器文档中找不到任何可以使它工作的东西。我按照AWS 文档中提到的方法让它工作了——创建一个 cloudTrail 来捕获事件,添加一个以状态机为目标的 cloudwatch 事件规则来触发状态机执行。
你能提到你想添加什么样的触发器吗?无服务器文档说只能添加 http 和预定事件来触发状态机。如果要添加任何其他事件触发器,则必须创建一个执行状态机的 lambda 函数并在 lambda 函数上添加触发器。
我想在 s3 事件上添加触发器。这对我有用:我使用 AWS CDK 来预置我的所有基础设施。为该存储桶创建一个 s3 存储桶和一个相应的 CloudTrail,以捕获 CDK 中的事件。遵循相同的代码片段:
const mybucket= new s3.Bucket(this, 'myBucket', {
bucketName: "my-bucket",
});
// cloud trail to log PutObject events to the s3 bucket
const trail = new cloudtrail.Trail(this, 'myBucketEventTrail');
// Adds an event selector to the bucket foo
trail.addS3EventSelector(
[
{
bucket: myBucket,
objectPrefix: 'input',
},
],
{
includeManagementEvents: false,
readWriteType: ReadWriteType.WRITE_ONLY,
}
);
您可以在此处查看 AWS CDK 。现在,您可以在 serverless.yml 的状态机定义中创建 CloudWatch 规则,以在 s3 事件上触发状态机。这是片段:
stepFunctions:
stateMachines:
my-step-functions:
name: my-state-machine
events:
- cloudwatchEvent:
event:
source:
- "aws.s3"
detail-type:
- "AWS API Call via CloudTrail"
detail:
eventName:
- "PutObject"
requestParameters:
bucketName:
- "my-bucket"
definition:
Comment: "My test state machine"
StartAt:...
...
现在,部署两者并测试触发器。上述方法适用于 s3 事件。如果您不想使用 CDK,您可以自己使用 CloudFormation 模板并创建 CloudTrail 和相应的 Cloudwatch 事件规则来触发您的状态机。
这是一个描述如何创建 CloudFormation 模板的博客。
希望有帮助!祝你好运!