3

I´m trying to get the ARN from a DynmoDB table created with @model from the api category.

The ARN is an output from the autogenerated cloudformation template under /amplify/backend/api/{api-name}/build/stacks.

I tried to import the ARN with the following statement in the EventSourceMapping for my Lambda function:

"EventSourceArn": {
                "Fn::ImportValue": {
                    "Fn::Join": [
                        ":",
                        [
                            {
                                "Ref": "apiGraphQLAPIIdOutput"
                            },
                            "GetAtt",
                            "CustomerTable",
                            "StreamArn"
                        ]
                    ]
                }
            },

But this throws the an error when pushing to the cloud:

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

I also added a dependsOn in the backend-config.json, which doesn’t resolve the problem

So, what would be the correct way to get this stream ARN in a cloudformation template of a lambda function?

Ersoy
  • 8,816
  • 6
  • 34
  • 48
Florian Fuchs
  • 133
  • 10
  • 1
    Currently, [I don't think there is a way](https://github.com/aws-amplify/amplify-cli/issues/997). However, there is an active & open [pull request](https://github.com/aws-amplify/amplify-cli/pull/2463) so this may change in the near future. – r.pedrosa Oct 31 '19 at 19:25

1 Answers1

4

So, I recently discovered it is indeed possible:

You must add this statement for allowing access to the stream in your policy:

    {
                            "Action": [
                                "dynamodb:*"
                            ],
                            "Effect": "Allow",
                            "Resource": [
                                {
                                    "Fn::ImportValue": {
                                        "Fn::Join": [
                                            ":",
                                            [
                                                {
                                                    "Ref": "apiGraphQLAPIIdOutput"
                                                },
                                                "GetAtt",
                                                "CustomerTable",
                                                "StreamArn"
                                            ]
                                        ]
                                    }
                                }
                            ]
                        }

And additionally, add this EventSourceMapping:

        "EventSourceArn": {
                    "Fn::ImportValue": {
                        "Fn::Join": [
                            ":",
                            [
                                {
                                    "Ref": "apiGraphQLAPIIdOutput"
                                },
                                "GetAtt",
                                "CustomerTable",
                                "StreamArn"
                            ]
                        ]
                    }
                }

Amplify is exporting the Stream ARNs in the folder

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

This worked for me in an existing project and also when setting up a new env.

Florian Fuchs
  • 133
  • 10