amazon-web-services - 使用 API 网关和 lambda 的 AWS 代码管道阶段批准不起作用
问题描述
我们有一个用于 Angular 应用程序构建和部署的 AWS 代码管道。
我添加了一个批准阶段,用户需要使用邮件中提供的链接进行批准。
以下是管道工作流程
- 当管道到达批准阶段时,它将向 SNS 主题发送邮件,邮件正文将包含批准和拒绝的链接。这些是 API 网关 URL,用于将管道详细信息和用户批准传递给集成 lambda。API url 示例:https ://xxxxx.execute-api.us-east-1.amazonaws.com/v0/pipeline-approval?action=Approved&pipeline=pipeline-name-here=release-approval&pipelineexecutionid=xxxxxxx
我收到的邮件包含来自 AWS 的 symantec 链接,https://clicktime.symantec.com/34RBC48WLEQRUG7Vc?u=https%3A%2F%xxxxx.execute-api.us-east-1.amazonaws。 com%2Fv0%2Fpipeline-approval%3Faction%3DApproved%26pipeline%3Dpiplinexxx%3Drelease-approval%26pipelineexecutionid%3xxxxxx
- 下面是lambda函数代码
import json
import logging
import re
import time
import boto3
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
MAX_WAIT_FOR_RESPONSE = 10
WAIT_INCREMENT = 1
def handler(event, context):
logger.info('REQUEST RECEIVED:\n %s', event)
logger.info('REQUEST RECEIVED:\n %s', context)
pipeline = event["queryStringParameters"]['pipeline']
stage = event["queryStringParameters"]['stage']
action = event["queryStringParameters"]['action']
approval_action = 'transition'
pipelineexecutionid = event["queryStringParameters"]['pipelineexecutionid']
client = boto3.client('codepipeline')
r = client.get_pipeline_state(name=pipeline)['stageStates']
print(r)
s = next((x for x in r if x['stageName'] == stage and x['latestExecution']['pipelineExecutionId'] == pipelineexecutionid ), None)
print(s)
s1 = s['actionStates']
print(s1)
s2 = next((y for y in s1 if y['actionName'] == approval_action ), None)
print(s2)
t = s2['latestExecution']['token']
print(t)
client.put_approval_result(
pipelineName=pipeline,
stageName=stage,
actionName=approval_action,
result={
'summary': 'Automatically approved by Lambda.',
'status': action
},
token=t
)
logger.info("Status message: %s", client.put_approval_result)
if action == 'Approved':
return {"statusCode": 200, "body": json.dumps('Thank you for approving the release!!')}
elif action == 'Rejected':
return {"statusCode": 200, "body": json.dumps('rejected.')}
问题是在到达批准阶段后,它会发送一封邮件,但它没有等待用户输入,它会在 2 到 5 秒内自动获得批准或拒绝。
请帮助我这里出了什么问题,为什么 Lambda 不等待 API 的响应以及为什么它会自动批准或拒绝。
解决方案
推荐阅读
- python - 如何在 python 中为烧瓶框架运行测试套件并获得代码覆盖率?
- ruby - 有没有办法在不改变 Ruby 中单词顺序的情况下反转字符串中的单个加扰单词?
- angular - 在 Angular 9 中动态加载 *ngFor 内的组件
- hadoop - Hive 安装错误:com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V
- c# - EF Core 未从 Web.Config 读取连接字符串
- sql - 如何在 SAS 中合并具有不同数据类型的 2 列?
- javascript - 检查特定的 URL 正则表达式
- linux - Git:尽管安装在 OpenWRT 的 USB 中,但找不到?
- c - 试图从分配的内存中用 fwrite() 填充文件
- prestashop-1.7 - 在管理产品页面(Prestashop)中添加一个复选框