AWS Pinpoint自定义渠道:无法正确调用挂钩中指定的Lambda函数

时间:2019-08-13 16:32:38

标签: aws-lambda amazon-iam aws-pinpoint

我正在尝试通过设置一个Campaign {ook来根据example documentation执行Lambda函数来为我的AWS Pinpoint项目创建一个(测试版)自定义渠道。

我的lambda函数似乎可以单独正常运行。但是,当我到达将CampaignHook指向lambda函数的地步时,就会出现此错误:

> aws lambda add-permission --function-name arn:aws:lambda:us-east-1:my-account-id:function:MyFunctionName \
    --statement-id s1 \
    --action lambda:InvokeFunction \
    --principal pinpoint.us-east-1.amazonaws.com \
    --source-arn 'arn:aws:mobiletargeting:us-east-1:my-account-id:/apps/my-pinpoint-project-id/campaigns/*'
=> 
{
    "Statement": "{\"Sid\":\"s1\",\"Effect\":\"Allow\",\"Principal\": {\"Service\":\"pinpoint.us-east-1.amazonaws.com\"},\"Action\":\"lambda:InvokeFunction\",\"Resource\":\"arn:aws:lambda:us-east-1:my-account-id:function:MyFunctionName\",\"Condition\":{\"ArnLike\":{\"AWS:SourceArn\":\"arn:aws:mobiletargeting:us-east-1:my-account-id:/apps/my-pinpoint-project-id/campaigns/*\"}}}"
}

> aws pinpoint update-application-settings \
    --application-id my-pinpoint-project-id \
    --write-application-settings-request '{\"CampaignHook\": { \"LambdaFunctionName\": \"arn:aws:lambda:us-east-1:my-account-id:function:MyFunctionName\", \"Mode\": \"DELIVERY\" }}'

=> An error occurred (BadRequestException) when calling the UpdateApplicationSettings operation: Could not properly invoke Lambda function specified in hook.

我的函数在C#中,并且处理程序的签名是:

public async Task<String> FunctionHandler(Object evt, ILambdaContext context)

知道错误消息是什么意思吗?我不确定这是权限问题还是命令本身有问题。

1 个答案:

答案 0 :(得分:1)

一个精确的项目的SourceARN应该如下所示:

arn:aws:mobiletargeting:us-east-1:my-account-id:/apps/my-pinpoint-project-id

我错误地为 campaign ARN添加了通配符。正确的命令是:

aws lambda add-permission --function-name arn:aws:lambda:us-east-1:my-account-id:function:MyFunctionName \
    --statement-id s1 \
    --action lambda:InvokeFunction \
    --principal pinpoint.us-east-1.amazonaws.com \
    --source-arn 'arn:aws:mobiletargeting:us-east-1:my-account-id:/apps/my-pinpoint-project-id'