AWS StepFunction:获取错误为 "error":"KeyError"

AWS StepFunction : Getting Error as "error": "KeyError"

我是 AWS 和 Step 函数的新手。我正在尝试 运行 使用 Lambda 函数从 Step 函数编写简单程序。我已尝试使用以下代码 运行 Step 函数。

代码:

import boto3
import json
import os



def lambda_handler(event, context):


    subject = event['Mail']['subject']
    toList = event['Mail']['mailTo'] 
    message = event['MailMessage']['message']
    status = ""


    body = message 

    subject="["+status+"]"+subject


    for to in toList.split(","):
        sendMail(to, ADMIN_EMAIL, subject, body)

    return event


def sendMail(to, reply, subject, body):
    client = boto3.client('ses', region_name=region_name)
    response = client.send_email(
        Source=reply,
        Destination={
            'ToAddresses': [
                to,
            ]
        },
        Message={
            'Subject': {
                'Data': subject,
            },
            'Body': {
                'Text': {
                    'Data': body,
                },
            }
        },
        ReplyToAddresses=[
            reply,
        ],
        ReturnPath=reply
    )
    return response

运行使用 Step 函数后,出现以下错误。

{
  "error": "KeyError",
  "cause": {
    "errorMessage": "'Mail'",
    "errorType": "KeyError",
    "stackTrace": [
      [
        "/var/task/lambda_function.py",
        11,
        "lambda_handler",
        "subject = event['Mail']['subject']"
      ]
    ]
  }
}

我的步骤函数:

{
  "Comment": "A Sample program to send an email",
  "StartAt": "SampleMail",
  "States": {
    "SampleMail": {
      "Type": "Task",
     "Resource": "arn:aws:lambda:us-west-1:000000123:function:TestEmail", 

      "End": true
    }
  }
}

你能告诉我我在这里缺少什么吗?

请帮助我。

非常感谢您的帮助。

传递给您的 lambda_handler 函数的 event 没有名为 "Mail" 的键,所以这一行

subject = event['Mail']['subject']

失败了。在使用该键检索任何值之前,您应该验证 event 参数是否具有 'Mail' 属性。