gpt4 book ai didi

amazon-web-services - 使用多个 UserParameters 从 CodePipeline 调用 Lambda

转载 作者:行者123 更新时间:2023-12-04 08:18:03 24 4
gpt4 key购买 nike

本教程展示如何通过传递单个参数从 CodePipeline 调用 Lambda:

http://docs.aws.amazon.com/codepipeline/latest/userguide/how-to-lambda-integration.html

我构建了一个需要获取 2 个参数的 slackhook lambda:

  • webhook_url
  • 消息

通过 CodePipeline 编辑器传入 JSON 会导致 JSON block 以“”形式发送,因此无法直接解析。

传入的用户参数:

{
"webhook":"https://hooks.slack.com/services/T0311JJTE/3W...W7F2lvho",
"message":"Staging build awaiting approval for production deploy"
}

事件负载中的用户参数

UserParameters: '{
"webhook":"https://hooks.slack.com/services/T0311JJTE/3W...W7F2lvho",
"message":"Staging build awaiting approval for production deploy"
}'

当尝试直接在 CLoudFormation 中应用多个 UserParameters 时,如下所示:

Name: SlackNotification
ActionTypeId:
Category: Invoke
Owner: AWS
Version: '1'
Provider: Lambda
OutputArtifacts: []
Configuration:
FunctionName: aws-notify2
UserParameters:
- webhook: !Ref SlackHook
- message: !Join [" ",[!Ref app, !Ref env, "build has started"]]
RunOrder: 1

创建错误 - 配置必须仅包含简单对象或字符串。

任何关于如何将多个 UserParameters 从 CloudFormation 模板传递到 Lambda 的猜测将不胜感激。

下面是 lambda 代码供引用: https://github.com/byu-oit-appdev/aws-codepipeline-lambda-slack-webhook

最佳答案

您应该能够将多个 UserParameters 作为单个 JSON 对象字符串传递,然后在收到后在 Lambda 函数中解析 JSON。

这正是 Python example 的方式文档中处理这种情况:

try:
# Get the user parameters which contain the stack, artifact and file settings
user_parameters = job_data['actionConfiguration']['configuration']['UserParameters']
decoded_parameters = json.loads(user_parameters)

类似地,使用 JSON.parse 在 Node.JS 中应该可以正常工作,将 JSON 对象字符串(如事件负载示例中所示)解析为可用的 JSON 对象:

> JSON.parse('{ "webhook":"https://hooks.slack.com/services/T0311JJTE/3W...W7F2lvho", "message":"Staging build awaiting approval for production deploy" }')
{ webhook: 'https://hooks.slack.com/services/T0311JJTE/3W...W7F2lvho',
message: 'Staging build awaiting approval for production deploy' }

关于amazon-web-services - 使用多个 UserParameters 从 CodePipeline 调用 Lambda,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41878412/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com