{"id":88,"date":"2019-02-21T11:03:04","date_gmt":"2019-02-21T03:03:04","guid":{"rendered":"http:\/\/jrblog.mooo.com\/john\/2019\/02\/21\/quick-start-to-get-or-post-aws-api-gateway-with-lambda-python\/"},"modified":"2019-02-21T11:03:04","modified_gmt":"2019-02-21T03:03:04","slug":"quick-start-to-get-or-post-aws-api-gateway-with-lambda-python","status":"publish","type":"post","link":"https:\/\/john.pentaidea.com\/?p=88","title":{"rendered":"Quick start to GET or POST AWS API gateway with Lambda python"},"content":{"rendered":"<p>Create Lambda for API GET<\/p>\n<ul>\n<li>\n<p>1. Create Lambda with python 3.6+<\/p>\n<\/li>\n<li>\n<p>2. Implement code<\/p>\n<\/li>\n<\/ul>\n<pre><code># Helper class to convert a DynamoDB item to JSON.\nclass DecimalEncoder(json.JSONEncoder):\n&nbsp;&nbsp;&nbsp;&nbsp;def default(self, o):\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if isinstance(o, decimal.Decimal):\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return str(o)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return super(DecimalEncoder, self).default(o)\n\n\ndef lambda_handler(event, context):\n&nbsp; &nbsp; # Get path parameter from GET\n&nbsp; &nbsp; inputParameter =&nbsp;event[&apos;pathParameters&apos;][&apos;Your_Parameter_Here&apos;]\n&nbsp;&nbsp; &nbsp;inputParameter = event[&apos;queryStringParameters&apos;][&apos;Your_Parameter_Here&apos;]\n\n&nbsp; &nbsp; # Get request body from POST\n&nbsp;&nbsp; &nbsp;input = json.loads(event[&apos;body&apos;])\n&nbsp;&nbsp; &nbsp;inputParameter =&nbsp;input[&apos;Your_Parameter_Here&apos;]\n&nbsp;&nbsp; &nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;return {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&apos;statusCode&apos;: 200,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&apos;body&apos;: &apos;callback(&apos; + json.dumps({ &quot;result&quot;:{ event }}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;, cls=DecimalEncoder) + &apos;)&apos;\n&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;\n<\/code><\/pre>\n<p>API Gateway &#8211; create endpoint<\/p>\n<ul>\n<li>\n<p>1. <span style=\"font-weight: bold\">APIs<\/span> -&gt; <span style=\"font-weight: bold\">Create API<\/span> -&gt; <span style=\"font-weight: bold\">Resource<\/span> -&gt; <span style=\"font-weight: bold\">Create Method<\/span> (GET\/POST) -&gt; Check&nbsp;<span style=\"font-weight: bold\">Use Lambda Proxy integration<\/span> -&gt; Choose <span style=\"font-weight: bold\">Lambda Function<\/span> (what you just create above)<\/p>\n<\/li>\n<li>\n<p>2. Deploy it -&gt; Get url -&gt; Start GET\/POST now.<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Create Lambda for API GET<\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[8],"class_list":["post-88","post","type-post","status-publish","format-standard","hentry","category-tech","tag-aws"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Quick start to GET or POST AWS API gateway with Lambda python - John&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/john.pentaidea.com\/?p=88\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Quick start to GET or POST AWS API gateway with Lambda python - John&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"Create Lambda for API GET\" \/>\n<meta property=\"og:url\" content=\"https:\/\/john.pentaidea.com\/?p=88\" \/>\n<meta property=\"og:site_name\" content=\"John&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-21T03:03:04+00:00\" \/>\n<meta name=\"author\" content=\"jj\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"jj\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/john.pentaidea.com\/?p=88\",\"url\":\"https:\/\/john.pentaidea.com\/?p=88\",\"name\":\"Quick start to GET or POST AWS API gateway with Lambda python - John&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\/\/john.pentaidea.com\/#website\"},\"datePublished\":\"2019-02-21T03:03:04+00:00\",\"dateModified\":\"2019-02-21T03:03:04+00:00\",\"author\":{\"@id\":\"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f\"},\"breadcrumb\":{\"@id\":\"https:\/\/john.pentaidea.com\/?p=88#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/john.pentaidea.com\/?p=88\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/john.pentaidea.com\/?p=88#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/john.pentaidea.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Quick start to GET or POST AWS API gateway with Lambda python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/john.pentaidea.com\/#website\",\"url\":\"https:\/\/john.pentaidea.com\/\",\"name\":\"John's Blog\",\"description\":\"\u4e16\u754c\u56e0\u601d\u7dd2\u800c\u8907\u96dc, \u4eba\u56e0\u5922\u60f3\u800c\u5049\u5927\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/john.pentaidea.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f\",\"name\":\"jj\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/john.pentaidea.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g\",\"caption\":\"jj\"},\"sameAs\":[\"https:\/\/john.pentaidea.com\"],\"url\":\"https:\/\/john.pentaidea.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Quick start to GET or POST AWS API gateway with Lambda python - John&#039;s Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/john.pentaidea.com\/?p=88","og_locale":"en_US","og_type":"article","og_title":"Quick start to GET or POST AWS API gateway with Lambda python - John&#039;s Blog","og_description":"Create Lambda for API GET","og_url":"https:\/\/john.pentaidea.com\/?p=88","og_site_name":"John&#039;s Blog","article_published_time":"2019-02-21T03:03:04+00:00","author":"jj","twitter_card":"summary_large_image","twitter_misc":{"Written by":"jj","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/john.pentaidea.com\/?p=88","url":"https:\/\/john.pentaidea.com\/?p=88","name":"Quick start to GET or POST AWS API gateway with Lambda python - John&#039;s Blog","isPartOf":{"@id":"https:\/\/john.pentaidea.com\/#website"},"datePublished":"2019-02-21T03:03:04+00:00","dateModified":"2019-02-21T03:03:04+00:00","author":{"@id":"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f"},"breadcrumb":{"@id":"https:\/\/john.pentaidea.com\/?p=88#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/john.pentaidea.com\/?p=88"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/john.pentaidea.com\/?p=88#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/john.pentaidea.com\/"},{"@type":"ListItem","position":2,"name":"Quick start to GET or POST AWS API gateway with Lambda python"}]},{"@type":"WebSite","@id":"https:\/\/john.pentaidea.com\/#website","url":"https:\/\/john.pentaidea.com\/","name":"John's Blog","description":"\u4e16\u754c\u56e0\u601d\u7dd2\u800c\u8907\u96dc, \u4eba\u56e0\u5922\u60f3\u800c\u5049\u5927","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/john.pentaidea.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f","name":"jj","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/john.pentaidea.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g","caption":"jj"},"sameAs":["https:\/\/john.pentaidea.com"],"url":"https:\/\/john.pentaidea.com\/?author=1"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/posts\/88","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=88"}],"version-history":[{"count":0,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/posts\/88\/revisions"}],"wp:attachment":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=88"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=88"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}