Akib Deraiya
Akib Deraiya

Reputation: 99

Use one dynamoDB table with two different serveless app

I have starting work on DynamoDB, Lambda function and serverless framework.

I have some knowledge of this all and still learning on this.

Now my point is that I crated one serverless app and deploy into AWS. In this app, I have created like 40+ endpoints(Lambda functions) and 4 dynamoDB tables like A, B, C, D.

Now I need to create another separate serverless app and I want to use dynamoDB table A into this app which I created into the previous serverless app.

Is it possible or not? If possible then how can I implement this.

I already try to scan operation into this new app but throughs error like

2018-06-07T11:02:19.352Z 3e8b6b27-6a42-11e8-acf9-7f86fa9df706 { AccessDeniedException: User: arn:aws:sts::XXXXXXX:assumed-role/serverless-rest-api-dev-us-east-1-lambdaRole/serverless-rest-api-dev-todoList is not authorized to perform: dynamodb:Scan on resource: arn:aws:dynamodb:us-east-1:XXXXXX:table/A

Here i need to define anything else related to dynamoDB table A into my new serverless.yml?

Please help me here if anyone is found the solution for this. Thanks in advance

Upvotes: 1

Views: 788

Answers (2)

Akib Deraiya
Akib Deraiya

Reputation: 99

I got the solution of my problem.

First, I need to check ARN of table A into AWS dynamoDB table section which i created into my first application.

Now add that ARN into second serverless application's serverless.yml file's Resource section.

Suppose my ARN of table A is like arn:aws:dynamodb:us-east-1:XXXXXX:table/todo-task

Now I need to add this ARN into my second app's serverless.yml file's Resource section. it's like

IAMRoleStatement
     - Effect: Allow
           Action:
                - dynamodb:*
           Resource:
                - arn:aws:dynamodb:us-east-1:XXXXXX:table/todo-task

Upvotes: 1

GiorgosDev
GiorgosDev

Reputation: 1767

If both applications and dynamoDB tables are located in same region it is possible. You should set a corresponding role for the second application to have access to Dynamo DB table. Please check permissions of role : serverless-rest-api-dev-us-east-1-lambdaRole/serverless-rest-api-dev-todoList

Upvotes: 0

Related Questions