Connect an application using serverless framework to an existing DynamoDB
Few things we need to know before we start:
- Serverless framework is a framework that helps develop, deploy, troubleshoot and secure your serverless applications and provide you with full serverless application lifecycle management. It works with many different cloud provider like AWS, Azure, Alibaba Cloud, … and very easy to install with multiple options for you to start with.
- DynamboDB is a NoSQL Database and is on of the Amazon Web Services.
Now, I assumed that you have your serveless app ready and connected to AWS provider. So, let’s get to the main part.
The file that manage connection between your serverless app and the database is
serverless.yml . When you install the serverless framework, it probably have
yml file ready to help you create table once you run your application.
If you want to connect your app to existing DB that you’ve created, first thing to do is comment out or remove below part:
Then, adjust the provider part as below. The
Resource: part is like a place where you define the address of your database. There’re serveral way to define this, either you put it in .env to make it secured or just put directly as below screenshot, becasue even if people see that address below, they still need your account to be able to access the db.
To find this arn, go to your table details in DynamoDB and copy the
Amazon Resource Name (ARN) . And voila, now try to test your api to add or edit the item in your table.
Although it seems extremely easy, if you’ve just started with Amazon services like i do, it’d take tons of time. So, i hope this helps.
I’m Linh from Goalist. See you in another story 😊