How to create a simple API with AWS using AWS API Gateway, DynamoDB, IAM?!

How to create a simple API with AWS using AWS API Gateway, DynamoDB, IAM?!

- 3 mins

Screenshot

Rest has become one of the most significant technologies for web applications. Its importance is likely to continue growing fast.

Rest is short for representational state transfer. The whole idea behind a restful API is that we can use it to transfer data around.

Let’s learn how to build an API using Amazon’s API gateway and Dynamodb table (Simple API) for clarifying in practice way.

Great so let know how to get a Dynamodb table to hook up to the API gateway? and to give me a publicly accessible API URL

1- Click on dynamoDB Screenshot Screenshot Screenshot I’m going to create a table to call this test the partition key is like the primary key, Lets going to call this (coracoid) just for the fun of it, For a string and use default settings should be fine. Screenshot let’s start doing that put a couple of lines to create an item and here you got crocoID and then will give it a string of 1, 2, 3 Screenshot

Create an item and below you got crocoID and then we’re going to give it a string of it. Change id name of a crocoid to any id.

{
  "crocoid": "1",
  "notes": "It's Always Day 1 at AWS",
  "Website": "www.demmahom.com"
}
{
  "crocoid": "2",
  "notes": "It will definitely work",
  "Website": "www.croco.ninja"
}
{
  "crocoid": "3",
  "notes": "Just repeat it",
  "Website": "www.cloudtea.net"
}

2- Choose ‘Create Policy’ to create new policy Screenshot Screenshot Screenshot

3- Choose ‘Create New Role’ and attach the policy that we already made before. Screenshot Screenshot Screenshot Screenshot Screenshot Screenshot

4- Choose ‘Amazon API Gateway’ and Get Started. We will create a New API name. Also, we’re going to call this dynamo test Screenshot Screenshot We need to create the resource and, we’re just going to call this crocoID the field that we’re going to use and so this is going to end up being the URL Screenshot Screenshot

Click on ‘Integration Request’ to mapping templates ‘application/json’ for a template to Amazon API gateway as a proxy for DynamoDB

{
    "TableName": "test",
    "PrimaryKey": "crocoid",
    "KeyConditionExpression": "crocoid = :v1",
    "ExpressionAttributeValues": {
        ":v1": {
            "S": "$input.params('myid')"
        }
    }
}

5- Click ‘test’ to do tests Screenshot Screenshot The first one I did was one so if we click one and click test it will work! Screenshot Screenshot

6- Click ‘Save’ and Replace callback ‘Key1 value is’ & Save and Test Screenshot Screenshot

Next thing you have to do is to deploy it. So, under actions select ‘deploy API’ deployment stage there’s going to be new. I’m going to call this test because that’s what everything else has been called deploy and now here it’s giving

Finally, publicly API URL Work fine!

Screenshot

comments powered by Disqus
rss facebook twitter github gitlab youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora quora