这是我从aws sns通知接收的json数据。我想访问Records->Sns->Message
中的deploymentGroupName
在我的lambda python代码中,我尝试这样做。
eventName = json.loads(event.Records[0].Sns.Message).deploymentGroupName;
这是我收到的json。
{
'Records': [{
'EventSource': 'aws:sns',
'EventVersion': '1.0',
'EventSubscriptionArn': 'arn:aws:sns:us-east-1:1236542:project-Deploy-Success:123-654-12-b177-123654',
'Sns': {
'Type': 'Notification',
'MessageId': '6ef313fa-46d2-5841-b162-4805edfb421c',
'TopicArn': 'arn:aws:sns:us-east-1:428219256379:project-Deploy-Success',
'Subject': 'SUCCEEDED: AWS CodeDeploy d-E8BYQ65CL in us-east-1 to project-code-deploy',
'Message': '{"region":"us-east-1","accountId":"213321213321","eventTriggerName":"Sandbox-Deployment-Triggered","applicationName":"project-code-deploy","deploymentId":"d-E8BYQ65CL","deploymentGroupName":"Sandbox-ec2-deployment","createTime":"Tue Nov 29 06:38:20 UTC 2022","completeTime":"Tue Nov 29 06:38:33 UTC 2022","deploymentOverview":"{\\"Succeeded\\":1,\\"Failed\\":0,\\"Skipped\\":0,\\"InProgress\\":0,\\"Pending\\":0}","status":"SUCCEEDED"}',
'Timestamp': '2022-11-29T06:38:33.558Z',
}
}]
}
现在马上给出这个错误。
[错误]名称错误:名称'json'未定义Traceback(最近的呼叫在最后):文件“/var/task/lambda_function.py”,第12行,在lambda_handler中,事件名称= json.loads(事件.记录[0].Sns.消息)。部署组名称;
1条答案
按热度按时间t3irkdon1#
如果
event
没有""
环境,则它已经转换为dict
。但是,您需要为Message
处理json
。输出: