我正在尝试从使用 API 类别中的 @model
创建的 DynmoDB 表中获取 ARN。
ARN 是 /amplify/backend/api/{api-name}/build/stacks
下自动生成的 cloudformation 模板的输出。
我尝试在 Lambda 函数的 EventSourceMapping 中使用以下语句导入 ARN:
"EventSourceArn": {
"Fn::ImportValue": {
"Fn::Join": [
":",
[
{
"Ref": "apiGraphQLAPIIdOutput"
},
"GetAtt",
"CustomerTable",
"StreamArn"
]
]
}
},
但这会在推送到云端时引发错误:
在堆栈“arn:aws:cloudformation:eu-central-1:124149422162:stack/myapp-stage-20191009174227-api-SHBHD6GIS7SD/5fb78d10-eaac-11e9-8a4c-0ac41be8cd2e”中找不到输出“GetAttCustomerTableStreamArn” '
我还在backend-config.json
中添加了dependsOn,但这并不能解决问题
那么,在 lambda 函数的 cloudformation 模板中获取此流 ARN 的正确方法是什么?
最佳答案
所以,我最近发现这确实是可能的:
您必须添加此语句以允许在您的策略中访问流:
{
"Action": [
"dynamodb:*"
],
"Effect": "Allow",
"Resource": [
{
"Fn::ImportValue": {
"Fn::Join": [
":",
[
{
"Ref": "apiGraphQLAPIIdOutput"
},
"GetAtt",
"CustomerTable",
"StreamArn"
]
]
}
}
]
}
此外,添加此 EventSourceMapping:
"EventSourceArn": {
"Fn::ImportValue": {
"Fn::Join": [
":",
[
{
"Ref": "apiGraphQLAPIIdOutput"
},
"GetAtt",
"CustomerTable",
"StreamArn"
]
]
}
}
Amplify 正在导出文件夹中的流 ARN
amplify\backend\api\{api_name}\build\stacks\{table_name}.json
这在现有项目中以及在设置新环境时对我有用。
关于aws-lambda - AWS Amplify 从使用 api 类别创建的 DynamoDB 表获取流 ARN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58308410/