Using API Gateway To Get Data From Dynamo DB Without Using AWS Lambda
Today I was stuck finding a solution on a very specific problem: to find a way that to get the data from Dynamo DB table without using Lambda service or without writing any piece of code in Lambda.
As you probably already know,that API Gateway has integration types.In that aws service is one which helps to connect to other services makes execution directly.Using these AWS services Let’s find a solution…!!!
Amazon API Gateway : Amazon API Gateway is an AWS service for creating, publishing, maintaining, monitoring, and securing REST and WebSocket APIs at any scale. API developers can create APIs that access AWS or other web services as well as data stored in the aws cloud.
There may be application-specific restrictions you’d like to place on the API calls being made to AWS services that you would not be able to enforce if clients integrated with the AWS APIs directly. You might want to enable your application to integrate with very specific functionality that an AWS service provides, without the need to manage access keys and secret keys that AWS APIs require.
In this, the client uses either GET, PUT, POST, DELETE methods in API Gateway and integrate with dynamo DB using aws service and get the data from a particular table. Without writing any piece of code in Lambda we can get the data from the table.
Steps for getting data from Dynamo-DB from API Gateway without using Lambda:
- Firstly log in to the aws console and Go to Services. In services click on DynamoDB.
- Select a table.
- View the details. And copy the ARN for further use.
Go to Services and click on IAM.
- Create Policy.
- Choose service.
- Click DynamoDB service. And add Actions.
- At Actions click on Query.
- Add the above ARN to this Resource.
- And then Review Policy.
- Give name to the policy. And create a policy.
- Your Policy is displayed here.
- Create a Role
- Click on API Gateway and then click on Next.
- Click on Next.
- Give your Role name and Create.
- Your Role will be displayed here.
- Click on Attach policies to attach the customised policy that we created before.
- Click on the policy you created and then click on Attach Policy.
- Your Policies will be displayed here.
- Go to Services and click on API Gateway. And then create a API.
- Give your API name and create.
- Give your Resource name and create a Resource.
- Create sub reource for your resource.
- Add method.
- Click on Intergation Request.
- Give the details and save.
- Click on Mapping Templates.
- Add a mapping template and save.
- Now, click on Test.
- Give your id that you want to test.
- It fetches the data from DB and gives Response.
- Click on Deploy API
- Give your stage name and click on deploy.
- It generates a URL.
- When you click on URL, it shows the response in this manner if the corresponding particular ID is Not in the DB.
- When you click on URL, it shows the response in this manner if the corresponding particular ID is In the DB.
Using this solution, we can directly get the data from Dynamo DB using API Gateway without writing any piece of code in Lambda function.
Ok, that’s it. I hope you found this case useful! See you next time.