{"id":6200,"date":"2019-07-24T01:13:33","date_gmt":"2019-07-24T01:13:33","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=6200"},"modified":"2019-07-24T01:13:33","modified_gmt":"2019-07-24T01:13:33","slug":"debugging-aws-services-with-lambda","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/","title":{"rendered":"Debugging AWS Services with Lambda"},"content":{"rendered":"<p>Say you have connectivity issues between AWS services in a VPC. Rather than change the existing system, you can debug it using a lambda that runs HTTP requests. I&#8217;ve included an example below. You can use this lambda to test many URLs and configurations quickly to find a range of problems.<\/p>\n<p>Note that to communicate with AWS services, you must &#8220;sign&#8221; AWS HTTP requests. This allows the destination AWS service to know what IAM role the lambda runs as. This example uses a library called aws4 to sign URLs. <\/p>\n<p>This lambda is small enough to edit through the AWS console, so you can fiddle with the requests once you have it deployed.<\/p>\n<pre lang=\"javascript\">\nexports.handler = (event, context, cb) => {\n  const aws4 = require('aws4');\n  const https = require('https');\n \n  \/\/ Update this to match the AWS url you want to test.\n  const signed = aws4.sign(\n    {\n      host: 'test.us-east-1.es.amazonaws.com', \n      path: '\/'\n    });\n \n  console.log(\"Requesting \" + signed);\n \n  https.get(signed, (resp) => {\n    let data = '';\n \n    resp.on('data', (chunk) => {\n      console.log('received ' + chunk);\n      data += chunk;\n    });\n \n    resp.on('end', () => {\n      console.log('DATA COMPLETE: ' + JSON.parse(data).explanation);\n      cb();\n    });\n  }).on(\"error\", (err) => {\n    console.log(\"ERRORED OUT: \" + err.message);\n \n    cb();\n  });\n};\n<\/pre>\n<p>Once you deploy this lambda, set the VPC, security group, subnets, and role and run it through the AWS console &#8211; you can name the test event anything you want. <\/p>\n<p>If the lambda times out, you likely have a network connectivity problem &#8211; e.g. a security group doesn&#8217;t allow outbound traffic, a firewall prevents traffic to the destination, etc. If you do have network connectivity but it fails quickly, you may have a problem with IAM roles or the HTTPS certificate on the destination. <\/p>\n<p>Note you can&#8217;t do npm install within a lambda because lambda has a readonly filesystem &#8211; I tried doing this first to create something you could just paste into the lambda console.<\/p>\n<p>The follow script will deploy &#8211; you can also drop the VPC settings entirely and set them through the console.<\/p>\n<pre lang=\"bash\">\nzip -r lambda.zip .\n \naws lambda create-function \\\n  --function-name test-lambda \\\n  --zip-file fileb:\/\/lambda.zip \\\n  --runtime 'nodejs10.x' \\\n  --handler 'index.handler' \\\n  --role 'arn:aws:iam::***:role\/***' \\\n  --vpc-config 'SubnetIds=subnet-***,subnet-***,SecurityGroupIds=sg-***'(base)\n<\/pre>\n<p><a href=\"https:\/\/github.com\/garysieling\/aws-test-lambda\">Full source here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A test lambda for AWS<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[8],"tags":[71,334],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"A test lambda for AWS\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"gary\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Gary Sieling - Software Engineer\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Debugging AWS Services with Lambda - Gary Sieling\" \/>\n\t\t<meta property=\"og:description\" content=\"A test lambda for AWS\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-07-24T01:13:33+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2019-07-24T01:13:33+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Debugging AWS Services with Lambda - Gary Sieling\" \/>\n\t\t<meta name=\"twitter:description\" content=\"A test lambda for AWS\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/debugging-aws-services-with-lambda\\\/#blogposting\",\"name\":\"Debugging AWS Services with Lambda - Gary Sieling\",\"headline\":\"Debugging AWS Services with Lambda\",\"author\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/author\\\/gary\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/#organization\"},\"datePublished\":\"2019-07-24T01:13:33+00:00\",\"dateModified\":\"2019-07-24T01:13:33+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/debugging-aws-services-with-lambda\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/debugging-aws-services-with-lambda\\\/#webpage\"},\"articleSection\":\"Devops, aws, lambda\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/debugging-aws-services-with-lambda\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.garysieling.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/category\\\/devops\\\/#listItem\",\"name\":\"Devops\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/category\\\/devops\\\/#listItem\",\"position\":2,\"name\":\"Devops\",\"item\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/category\\\/devops\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/debugging-aws-services-with-lambda\\\/#listItem\",\"name\":\"Debugging AWS Services with Lambda\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/debugging-aws-services-with-lambda\\\/#listItem\",\"position\":3,\"name\":\"Debugging AWS Services with Lambda\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/category\\\/devops\\\/#listItem\",\"name\":\"Devops\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/#organization\",\"name\":\"Gary Sieling\",\"description\":\"Software Engineer\",\"url\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/author\\\/gary\\\/#author\",\"url\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/author\\\/gary\\\/\",\"name\":\"gary\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/debugging-aws-services-with-lambda\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0be925276d848ffe98a6a9dc8cf33e67?s=96&d=identicon&r=g\",\"width\":96,\"height\":96,\"caption\":\"gary\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/debugging-aws-services-with-lambda\\\/#webpage\",\"url\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/debugging-aws-services-with-lambda\\\/\",\"name\":\"Debugging AWS Services with Lambda - Gary Sieling\",\"description\":\"A test lambda for AWS\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/debugging-aws-services-with-lambda\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/author\\\/gary\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/author\\\/gary\\\/#author\"},\"datePublished\":\"2019-07-24T01:13:33+00:00\",\"dateModified\":\"2019-07-24T01:13:33+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/\",\"name\":\"Gary Sieling\",\"description\":\"Software Engineer\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Debugging AWS Services with Lambda - Gary Sieling","description":"A test lambda for AWS","canonical_url":"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/#blogposting","name":"Debugging AWS Services with Lambda - Gary Sieling","headline":"Debugging AWS Services with Lambda","author":{"@id":"https:\/\/www.garysieling.com\/blog\/author\/gary\/#author"},"publisher":{"@id":"https:\/\/www.garysieling.com\/blog\/#organization"},"datePublished":"2019-07-24T01:13:33+00:00","dateModified":"2019-07-24T01:13:33+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/#webpage"},"isPartOf":{"@id":"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/#webpage"},"articleSection":"Devops, aws, lambda"},{"@type":"BreadcrumbList","@id":"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.garysieling.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.garysieling.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.garysieling.com\/blog\/category\/devops\/#listItem","name":"Devops"}},{"@type":"ListItem","@id":"https:\/\/www.garysieling.com\/blog\/category\/devops\/#listItem","position":2,"name":"Devops","item":"https:\/\/www.garysieling.com\/blog\/category\/devops\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/#listItem","name":"Debugging AWS Services with Lambda"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.garysieling.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/#listItem","position":3,"name":"Debugging AWS Services with Lambda","previousItem":{"@type":"ListItem","@id":"https:\/\/www.garysieling.com\/blog\/category\/devops\/#listItem","name":"Devops"}}]},{"@type":"Organization","@id":"https:\/\/www.garysieling.com\/blog\/#organization","name":"Gary Sieling","description":"Software Engineer","url":"https:\/\/www.garysieling.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.garysieling.com\/blog\/author\/gary\/#author","url":"https:\/\/www.garysieling.com\/blog\/author\/gary\/","name":"gary","image":{"@type":"ImageObject","@id":"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/0be925276d848ffe98a6a9dc8cf33e67?s=96&d=identicon&r=g","width":96,"height":96,"caption":"gary"}},{"@type":"WebPage","@id":"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/#webpage","url":"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/","name":"Debugging AWS Services with Lambda - Gary Sieling","description":"A test lambda for AWS","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.garysieling.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/#breadcrumblist"},"author":{"@id":"https:\/\/www.garysieling.com\/blog\/author\/gary\/#author"},"creator":{"@id":"https:\/\/www.garysieling.com\/blog\/author\/gary\/#author"},"datePublished":"2019-07-24T01:13:33+00:00","dateModified":"2019-07-24T01:13:33+00:00"},{"@type":"WebSite","@id":"https:\/\/www.garysieling.com\/blog\/#website","url":"https:\/\/www.garysieling.com\/blog\/","name":"Gary Sieling","description":"Software Engineer","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.garysieling.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Gary Sieling - Software Engineer","og:type":"article","og:title":"Debugging AWS Services with Lambda - Gary Sieling","og:description":"A test lambda for AWS","og:url":"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/","article:published_time":"2019-07-24T01:13:33+00:00","article:modified_time":"2019-07-24T01:13:33+00:00","twitter:card":"summary_large_image","twitter:title":"Debugging AWS Services with Lambda - Gary Sieling","twitter:description":"A test lambda for AWS"},"aioseo_meta_data":{"post_id":"6200","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2023-02-04 17:20:44","updated":"2026-07-06 02:32:43","ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.garysieling.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.garysieling.com\/blog\/category\/devops\/\" title=\"Devops\">Devops<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tDebugging AWS Services with Lambda\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.garysieling.com\/blog"},{"label":"Devops","link":"https:\/\/www.garysieling.com\/blog\/category\/devops\/"},{"label":"Debugging AWS Services with Lambda","link":"https:\/\/www.garysieling.com\/blog\/debugging-aws-services-with-lambda\/"}],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/6200"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=6200"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/6200\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=6200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=6200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=6200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}