从 AWS CodePipeline 调用 AWS Lambda 函数时权限被拒绝

Permission denied when calling AWS Lambda function from AWS CodePipeline

我已将管道设置为调用 AWS Lamba 函数。 运行10 分钟后,这是我得到的错误:

Action execution failed The AWS Lambda function addAMIToAutoScalingLC failed to return a result. Check the function to verify that it has permission to call the PutJobSuccessResult action and that it made a call to PutJobSuccessResult.

日志本身不包含相关信息。

我认为我的 IAM 权限设置正确:

我认为我的脚本调用了 PutJobSuccessResult 因为当我测试脚本时我得到了 Execution result: succeeded.

我的脚本不需要任何参数,所以我没有在 CodePipeline 中提供任何用户参数。

我应该怎么做才能进一步调查?

找到答案了。问题不是来自许可,而是来自没有调用 PutJobSuccessResult: 管道不知道lambda函数已经完成,所以一直等到超时。

这段代码解决了问题 (Python):

import boto3
pipeline = boto3.client('codepipeline')

def lambda_handler(event, context):

    # stuff

    response = pipeline.put_job_success_result(
        jobId=event['CodePipeline.job']['id']
    )
    return response