我需要运行 EKS 作业来执行特定任务。流程是这样的,StepFunction 有 3 个阶段(stage1、stage2、stage3)。每个阶段都有特定的任务要做,并且有一个可在 AWS ECR 中使用的 docker 映像。 Stage1 应触发 EKS 作业,以便创建 pod 并执行此 image1。然后它会进入Stage2等等。
由于 StepFunction 无法直接与 EKS 专用端点通信,因此我想引入 lambda。
我正在寻找cloudformation脚本。有人可以帮助我执行此流程吗?
Step Functions 的工作流程:
触发 EKS 作业:
CloudFormation 模板:
AWSTemplateFormatVersion: '2010-09-09'
Resources:
# IAM Role for Step Function Execution
StepFunctionExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- states.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: StepFunctionPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource: "*"
# IAM Role for Lambda Functions
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: LambdaExecutionPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- eks:DescribeCluster
- eks:ListClusters
- eks:DescribeUpdate
- eks:CreateFargateProfile
- eks:CreateNodegroup
- eks:DeleteNodegroup
- eks:DeleteFargateProfile
- logs:CreateLogStream
- logs:PutLogEvents
Resource: "*"
# Lambda Function for Stage1 (EKS Job Trigger)
Stage1Lambda:
Type: AWS::Lambda::Function
Properties:
Handler: index.handler
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: nodejs16x
Code:
ZipFile: |
var aws=Require("aws-sdk");Function `Handlern!