What you may not realise though, is that Postgres supports JSON pretty much equally well. I will add more scripts and templates to it over time, rounding off the functionality as I evolve in my understanding of deploying API using AWS RDS, Lambda, and API Gateway.One of the things that made NoSQL databases like MongoDB so popular was how easy it is to just throw a blob of JSON in, when that’s what you needed. This is why I’ve added it to my API Evangelist toolbox, giving me a simple, forkable set of scripts I can use as a seed for any new API. It should provide a base template you can use to seed any basic data API. If you apply the Lambda scripts, make sure you upload individually as zipped files, so that the mysql dependencies are there, otherwise the script won’t connect to the database. #Nodejs api aws postgresql code#I have all the code on Github, and will be evolving as I push it forward. It provides a pretty solid, scalable, manageable way to deploy an API using AWS. The process has opened my eyes up wider to the serverless world, as well as playing more with Node.js–which has been on my list for some time now. Hopefully it provides a basic example of an API using RDS, Lambda, and API Gateway, which is something I have wanted to have in my toolbox for some time. I will work on other parts in future posts. There are other things you have to do, like setting up a usage plan, turning on API key access for each API, and setting up custom domain if you want, but hopefully this simple gets the point across. If you don’t the item_id won’t be passed on to the Lambda function–it took me a while to get this one. You have to setup a body mapping to the item_id when passed in the path for the PUT, GET, and DELETE functions. There is one thing you have to do to make each method work properly with the Lambda function. Now, I just need to wire up each API method to its accompanying Lambda function, something API Gateway makes easy. This gives me the skeleton framework for my API, with the paths and methods I need to accomplish the basics of reading and writing data. I am using AWS API Gateway as the API layer, and to setup I’m just importing an OpenAPI definition to jumpstart things: Now that I have the business logic setup in AWS Lambda for reading, and writing data to my relational database I want an API front-end for this backend setup. Then of course be able to get a single record:Īnd of course I want to be able to delete records: I opted to use Node.js running in Lambda for the code layer of this API, starting with the ability to get all records from the database:Īfter that I want to be able to insert new records: Next I wanted to have the basic CRUD operations for my API. I’m just playing around with different configurations and pushing forward my understanding of what is possible, and this week I switched out the database in this with AWS RDS, which opens up the ability to use MySQL or Postgres as the backend for any API.įor this example, I’m using a simple items database, which you can build with this SQL script after you fire up an RDS instance (I’m using MySQL): One benefit of going this route is that you can even bypass Lambda, as the AWS API Gateway can work directly with AWS DynamoDB API. I like this approach because of the simple nature of AWS DynamoDB. I wrote about a simple API with AWS DynamoDB, Lambda, and API Gateway last week.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |