【问题标题】:AWS Amplify get Stream ARN from a DynamoDB Table created with api categoryAWS Amplify 从使用 api 类别创建的 DynamoDB 表中获取流 ARN
【发布时间】:2019-10-09 16:22:15
【问题描述】:

我正在尝试从使用 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"
                        ]
                    ]
                }
            },

但这会在推送到云端时引发错误:

Output 'GetAttCustomerTableStreamArn' not found in stack 'arn:aws:cloudformation:eu-central-1:124149422162:stack/myapp-stage-20191009174227-api-SHBHD6GIS7SD/5fb78d10-eaac-11e9-8a4c-0ac41be8cd2e'

我还在backend-config.json中添加了一个dependsOn,并没有解决问题

那么,在 lambda 函数的 cloudformation 模板中获取此流 ARN 的正确方法是什么?

【问题讨论】:

标签: aws-lambda amazon-cloudformation aws-amplify amazon-dynamodb-streams


【解决方案1】:

所以,我最近发现确实有可能:

您必须在策略中添加此语句以允许访问流:

    {
                            "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 正在导出文件夹中的 Stream ARN

amplify\backend\api\{api_name}\build\stacks\{table_name}.json

这在现有项目中以及在设置新环境时对我有用。

【讨论】:

    猜你喜欢
    • 2022-08-11
    • 1970-01-01
    • 2020-11-12
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多