{"id":18909468,"url":"https://github.com/gakas14/api_gateway_lambda_dynamodb","last_synced_at":"2026-03-07T00:30:20.498Z","repository":{"id":209586451,"uuid":"724451239","full_name":"gakas14/API_Gateway_Lambda_DynamoDb","owner":"gakas14","description":"Build an API Gateway with Lambda and DynamoDB","archived":false,"fork":false,"pushed_at":"2024-01-05T14:29:16.000Z","size":3402,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-31T12:34:16.230Z","etag":null,"topics":["apigateway","aws","dynamodb","lambda-functions","serverless"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gakas14.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-28T05:15:57.000Z","updated_at":"2023-11-28T07:02:12.000Z","dependencies_parsed_at":"2024-01-05T15:38:36.327Z","dependency_job_id":"2075b094-5e9b-4e1b-a625-5b5d091dbb7e","html_url":"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb","commit_stats":null,"previous_names":["gakas14/api_gateway_lambda_dynamodb"],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gakas14%2FAPI_Gateway_Lambda_DynamoDb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gakas14%2FAPI_Gateway_Lambda_DynamoDb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gakas14%2FAPI_Gateway_Lambda_DynamoDb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gakas14%2FAPI_Gateway_Lambda_DynamoDb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gakas14","download_url":"https://codeload.github.com/gakas14/API_Gateway_Lambda_DynamoDb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239896947,"owners_count":19715124,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apigateway","aws","dynamodb","lambda-functions","serverless"],"created_at":"2024-11-08T09:33:55.002Z","updated_at":"2026-03-07T00:30:20.351Z","avatar_url":"https://github.com/gakas14.png","language":null,"readme":"# API_Gateway_Lambda_DynamoDB\nWe created one resource (DynamoDBManager) and defined one method (POST). A Lambda function backs the API. Amazon API Gateway invokes the Lambda function when you call the API through an HTTPS endpoint.\n\nThe POST method on the DynamoDBManager resource supports the following DynamoDB operations:\n\nCreate, update, and delete an item.\nRead an item.\nScan an item.\n\n\n![Api_Lambda_DynamoDB](https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/8d8e58a0-ecec-48a6-8348-250a9334573b)\n\n\n\nI. Create a lambda role and function:\n\n1. Create a lambda role with permission to DynamoDB and CloudWatch Logs.\n\n\u003cimg width=\"1259\" alt=\"lambda_role\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/f19c8839-9f38-441f-a79e-42d207060a81\"\u003e\n\n\u003cimg width=\"1271\" alt=\"lambda\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/3983f56b-48ed-4e29-ba1d-8e5a671c648d\"\u003e\n\n\n\n3. Create the lambda function:\n\ncreate the lambda function name \"apigateway_lambda_function,\" runtime with Python latest version, with execution role choose the lambda role created previously\n   \n   \u003cimg width=\"1262\" alt=\"create_lambda_function1\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/897dd9a0-0d6d-4cd9-bb0a-766b775e2758\"\u003e\n\n\n   \u003cimg width=\"1256\" alt=\"create_lambda_function2\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/f30d6089-793b-4d81-ae34-2e5638544936\"\u003e\n\n\n   Replace the boilerplate coding with the following code snippet and click \"Save\"\n\n   Python Code\n\n      import boto3\n   \n      import json\n   \n      from __future__ import print_function\n      \n      print('Loading function')\n   \n      def lambda_handler(event, context):\n       '''Provide an event that contains the following keys:\n         - operation: one of the operations in the operations dict below\n         - tableName: required for operations that interact with DynamoDB\n         - payload: a parameter to pass to the operation being performed\n       '''\n   \n       \toperation = event['operation']\n       \tif 'tableName' in event:\n           \tdynamo = boto3.resource('dynamodb').Table(event['tableName'])\n       \toperations = {\n           \t'create': lambda x: dynamo.put_item(**x),\n           \t'read': lambda x: dynamo.get_item(**x),\n           \t'update': lambda x: dynamo.update_item(**x),\n           \t'delete': lambda x: dynamo.delete_item(**x),\n            'list': lambda x: dynamo.scan(**x),\n            'echo': lambda x: x,\n            'ping': lambda x: 'pong'\n       \t}\n   \n       \tif operation in operations:\n        \t\treturn operations[operation](event.get('payload'))\n       \telse:\n           \t\traise ValueError('Unrecognized operation \"{}\"'.format(operation))\n\n\n\n5. Test Lambda Function\n   \n    \u003cimg width=\"1277\" alt=\"test_event\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/54210384-7008-4a4a-a6bd-77f25d4a7524\"\u003e\n\n    \u003cimg width=\"1274\" alt=\"create_test_event\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/8c311a39-eee6-4d0f-89d8-ac66a580cf89\"\u003e\n\n\n    \u003cimg width=\"1267\" alt=\"test_lambda\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/1e2c9783-d3ab-4d92-adba-4fd5b8949029\"\u003e\n\n\n\n    With status 200, meaning the lambda function is working. \n\n\n\nII. Create DynamoDB Table\n\nCreate the DynamoDB table that the Lambda function uses, with table name \"apigate_table,\" partition key as \"table_id,\" with default settings.\n\n \u003cimg width=\"1261\" alt=\"table_name\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/b2576f07-cbaf-4001-8ed7-ef378a01fde3\"\u003e\n\n\n\n\nIII. Create API\n\n1.create a rest API call \"lambda_DynamoDB_ops\" \n\n\u003cimg width=\"1268\" alt=\"create_rest_api\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/82042e3e-007a-46f5-a970-042824e371fc\"\u003e\n\n\n\n2. add resource call \"DynamoDBManager\" with path \"/\"\n   \n\u003cimg width=\"1277\" alt=\"create_resource\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/236a587a-ed24-4f94-840a-cba527be6490\"\u003e\n\n\n\n3. Let's create a POST Method for our API, select the lambda function we create\n   \n\u003cimg width=\"1261\" alt=\"create_method\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/d49efd5e-64c4-4a79-9b19-72a406fd9f92\"\u003e\n\n\n   \u003cimg width=\"1261\" alt=\"add_lambda\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/c9f35527-e7af-41e6-9add-c2be5bc35694\"\u003e\n\n\n\n\n5. Deploy the API\n   \nSelect a new stage and give it a name, then deploy the API\n   \n![deploy](https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/367bdebb-b989-4d8a-98da-5e097ecbcb39)\n\n\n\n\n6. Running the solution\n   \nTo execute our API from the local machine, we are going to use the Curl command. You can choose to use Postman\n\n\n$ curl -X POST -d \"{\\\"operation\\\":\\\"create\\\",\\\"tableName\\\":\\\"apigate_table\\\",\\\"payload\\\":{\\\"Item\\\":{\\\"table_id\\\":\\\"1\\\",\\\"name\\\":\\\"Bob\\\"}}}\" https://$API.execute-api.$REGION.amazonaws.com/production/DynamoDBManager\n\n\n\nTo validate that the item is indeed inserted into the DynamoDB table\n\n\n\u003cimg width=\"1271\" alt=\"list_of_items\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/a6147cb5-040d-4c34-afd3-623f1d90423c\"\u003e\n\n\n\nAdd a second item.\n\n\u003cimg width=\"570\" alt=\"add_second_item\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/be06d853-fdfb-475c-8431-7a938426fc1e\"\u003e\n\n\n\n\u003cimg width=\"1271\" alt=\"list_of_items\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/08d028bc-42aa-4fe1-ae2c-a0124a2c6f12\"\u003e\n\n\n\nList the items via curl.\n\n\n{\n    \"operation\": \"list\",\n    \"tableName\": \"apigate_table\",\n    \"payload\": {\n    }\n}\n\n\n\u003cimg width=\"1192\" alt=\"list_all_items\" src=\"https://github.com/gakas14/API_Gateway_Lambda_DynamoDb/assets/74584964/9ff11778-7d2f-44df-850a-e4bd16c83800\"\u003e\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgakas14%2Fapi_gateway_lambda_dynamodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgakas14%2Fapi_gateway_lambda_dynamodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgakas14%2Fapi_gateway_lambda_dynamodb/lists"}