CDK中现有lambda的步骤功能任务 [英] Step functions task for existing lambda in CDK

查看:79
本文介绍了CDK中现有lambda的步骤功能任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CDK的新手,我们有现有的lambda资源,我想将lambda函数用作CDK中的任务.RunLambdaTask期望使用lambda函数.有没有办法从arn获取lambda函数?

I am new to CDK and we have existing lambda resource and I want to use the lambda function as task in CDK. RunLambdaTask is expecting the lambda function. Is there a way to get the lambda function from the arn?

       submit_job = sfn.Task(
            self, "Submit Job",

            task=sfn_tasks.RunLambdaTask("how to get the lambda function")
            result_path="$.guid",
        )

推荐答案

为了使用ARN获得lambda函数,您需要使用- lambda.Function.fromFunctionArn .

In order to get the lambda function using ARN you need to use - lambda.Function.fromFunctionArn.

用法:

const lambdaARN = `arn:aws:lambda:${region}:${accountID}:function:${lambdaName}`
const importedLambda = lambda.Function.fromFunctionArn(scope,'importedLambda',lambdaARN)

完整示例:

      createRunLambdaTask(scope: cdk.Construct,lambdaARN: string,resultPath: string,duration: number = 1200,name: string): sfn.Task {
      const importedLambda = lambda.Function.fromFunctionArn(scope,`${name}-lambda`,lambdaARN)
      const task = new Task(scope, name, {
        resultPath: resultPath,
        timeout: Duration.seconds(duration),
        task: new tasks.RunLambdaTask(importedLambda, {
          integrationPattern: sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN,
          payload: {
            "token.$": sfn.Context.taskToken,
            "Input.$": "$"
          },
        })
      });
      return task;
    }

有关 更新-

我刚刚注意到您使用Python而不是Typescript.基本上,这是相同的实现.遵循 from_function_arn有关如何导入现有lambda的文档.

I have just noticed you work with Python and not Typescript. basically, this is the same implementation. Follow from_function_arn documentation about how to import existing lambda.

然后将 IFucntion 对象传递给 RunLambdaTask .

这篇关于CDK中现有lambda的步骤功能任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆