AWS---AWS Step Functions创建--未完待续。。。

1. aws 的IAM 页面,新建一个 role,界面如下

2. step function页面,新建一个state machine

step function页面选择get started,或者create

在role 这个选项里,选择步骤1创建的role

3. 再创建一个role

跳转到lambda页面,再创建一个role,这次service选择lambda

接着在下一页的policy中搜索并选中:AWSStepFunctionsFullAccess 和CloudWatchLogsFullAccess

4. 跳转到lambda页面

写函数代码如下:

import boto3
import os
import json

stepfunctions = boto3.client('stepfunctions')

def lambda_handler(event, context):
    
    bucket = event['Records'][0]['s3']['bucket']['name']
    key = event['Records'][0]['s3']['object']['key']
    
    input = {
        "Bucket" : bucket,
        "Key": key
    }
    
    response = stepfunctions.start_execution(
        stateMachineArn=os.environ['STATEMACHINEARN'],
        input=json.dumps(input, default=str)
    )
    
    return json.dumps(response, default=str)

并填写变量env:  STATEMACHINEARN为 变量名,value的值需要跳转到Step Functions页面拷贝其ARN码。

5. S3中触发

在S3的bucket中的properties中的Events卡,删除现有的event notification,然后新添加一个notification,里面的sendto和lambda选择步骤4中创建的lambda名

6. Step function

在step function中,

  1. Generate code snippet menu, select AWS Lambda: Invoke a function and select the full ARN for the lab-lambda-transcribe function.

  2. Use the Copy to clipboard button to copy the definition snippet to your computer's clipboard.

  3. Carefully paste this definition snippet into the main definition over the whole of the HelloWorld state. To see what this should look like, check the video in this lab.

  4. Fix the validation errors:

    • Change the name of the pasted state to transcribe.
    • Update the StartAt value to transcribe.
    • Change the Next key and value to "End": true.
  5. Click Save > Save anyway.

未完待续。。。

发布了140 篇原创文章 · 获赞 80 · 访问量 36万+

猜你喜欢

转载自blog.csdn.net/daiqinge/article/details/103515619
AWS
今日推荐