{"id":83872,"date":"2018-11-24T15:05:29","date_gmt":"2018-11-24T13:05:29","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=83872"},"modified":"2018-11-23T13:20:41","modified_gmt":"2018-11-23T11:20:41","slug":"build-restful-api-go-using-aws-lambda","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html","title":{"rendered":"Build a RESTful API in Go using AWS Lambda"},"content":{"rendered":"<p>In this post we\u00a0will\u00a0learn to design, build, and deploy a RESTful API in Go using AWS Lambda. Before starting, let me give you a brief introduction about AWS Lambda.<\/p>\n<p><strong>What is AWS Lambda?<\/strong><br \/>\nAWS Lambda is a\u00a0serverless compute\u00a0service that runs our code in response to events and automatically manages the underlying compute resources for us. We can use AWS Lambda to extend other AWS services with custom logic, or create our own back-end services that operate at AWS scale, performance, and security. AWS Lambda can automatically run code in response to\u00a0multiple events, such as HTTP requests via\u00a0Amazon API Gateway, modifications to objects in\u00a0Amazon S3\u00a0buckets, table updates in\u00a0Amazon DynamoDB, and state transitions in\u00a0AWS Step Functions.<\/p>\n<p>Lambda runs our code on high-availability compute infrastructure and performs all the administration of the compute resources, including server and operating system maintenance, capacity provisioning and automatic scaling, code and security patch deployment, and code monitoring and logging. All we need to do is supply the code.<\/p>\n<p>Now, lets\u2019 start with building an API that will help a local movie rental shop in managing their available movies.<\/p>\n<h2>API architecture<\/h2>\n<p>The following diagram shows how the API Gateway and Lambda fit into the API architecture:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image1.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83886 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image1.png\" alt=\"RESTful API\" width=\"333\" height=\"301\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image1.png 333w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image1-300x271.png 300w\" sizes=\"(max-width: 333px) 100vw, 333px\" \/><\/a><\/p>\n<p>AWS Lambda empowers microservice development. That being said, each endpoint triggers a different Lambda function. These functions are independent of one another and can be written in different languages, thereby leading to scaling at function level, easier unit testing, and loose coupling.<\/p>\n<p>All requests from clients first go\u00a0through\u00a0the API Gateway. It then routes the incoming request to the right Lambda function accordingly.<\/p>\n<p>Note that a single Lambda function can Handle multiple HTTP methods (<strong>GET<\/strong>, <strong>POST<\/strong>, <strong>PUT<\/strong>, <strong>DELETE<\/strong>, and so on). It\u2019s advisable to create multiple Lambda functions for each functionality in order to leverage the power of microservices. However, building a single Lambda function to handle multiple endpoints could be a good exercise.<\/p>\n<h2>Endpoints design<\/h2>\n<p>Now that the\u00a0architecture\u00a0has been defined, it\u2019s time to go through the implementation of the functionalities described in the above diagram.\u00a0Instead of hard coding the HTTP status code, you can use the <strong>net\/http<\/strong> Go package and use a built-in status code variables such as <strong>http.StatusOK<\/strong>, <strong>http.StatusCreated<\/strong>, <strong>http.StatusBadRequest<\/strong>, <strong>http.StatusInternalServerError<\/strong>, and so on.<\/p>\n<h2>The GET method<\/h2>\n<p>The first feature to\u00a0implement\u00a0is listing movies. That\u2019s where the\u00a0<strong>GET\u00a0<\/strong>method comes into play. Lets\u2019 start with it following steps:<\/p>\n<p><strong>Step 1:<\/strong> Create a Lambda function that registers a\u00a0<strong>findAll\u00a0<\/strong>handler. This handler transforms a list of\u00a0movies to a\u00a0string and then returns this string wrapped by the\u00a0<strong>APIGatewayProxyResponse\u00a0<\/strong>variable along with a <strong>200<\/strong> HTTP status code. It also handles errors in case of conversion failure. The handler implementation is as follows:<\/p>\n<pre class=\"brush:java\">package main\r\n\r\nimport (\r\n  \"encoding\/json\"\r\n\r\n  \"github.com\/aws\/aws-lambda-go\/events\"\r\n  \"github.com\/aws\/aws-lambda-go\/lambda\"\r\n)\r\n\r\nvar movies = []struct {\r\n  ID int `json:\"id\"`\r\n  Name string `json:\"name\"`\r\n}{\r\n    {\r\n      ID: 1,\r\n      Name: \"Avengers\",\r\n    },\r\n    {\r\n      ID: 2,\r\n      Name: \"Ant-Man\",\r\n    },\r\n    {\r\n      ID: 3,\r\n      Name: \"Thor\",\r\n    },\r\n    {\r\n      ID: 4,\r\n      Name: \"Hulk\",\r\n    }, {\r\n      ID: 5,\r\n      Name: \"Doctor Strange\",\r\n    },\r\n}\r\n\r\nfunc findAll() (events.APIGatewayProxyResponse, error) {\r\n  response, err := json.Marshal(movies)\r\n  if err != nil {\r\n    return events.APIGatewayProxyResponse{}, err\r\n  }\r\n\r\n  return events.APIGatewayProxyResponse{\r\n    StatusCode: 200,\r\n    Headers: map[string]string{\r\n      \"Content-Type\": \"application\/json\",\r\n    },\r\n    Body: string(response),\r\n  }, nil\r\n}\r\n\r\nfunc main() {\r\n  lambda.Start(findAll)\r\n}<\/pre>\n<p>Instead of hard coding the HTTP status code, you can use the <strong>net\/http<\/strong> Go package and use a built-in status code variables such as <strong>http.StatusOK<\/strong>, <strong>http.StatusCreated<\/strong>, <strong>http.StatusBadRequest<\/strong>, <strong>http.StatusInternalServerError<\/strong>, and so on.<\/p>\n<p><strong>Step 2:<\/strong> Create a script file with the following content to build a Lambda function deployment package, a <strong>.zip<\/strong> file consisting of your code and any dependencies, as follows:<\/p>\n<pre class=\"brush:java\">#!\/bin\/bash\r\n\r\necho \"Build the binary\"\r\nGOOS=linux GOARCH=amd64 go build -o main main.go\r\n\r\necho \"Create a ZIP file\"\r\nzip deployment.zip main\r\n\r\necho \"Cleaning up\"\r\nrm main<\/pre>\n<p><strong>Step 3:<\/strong>\u00a0Execute the following commands to build the deployment package as <strong>.zip<\/strong> file:<\/p>\n<pre class=\"brush:java\">$ chmod +x build.sh\r\n$ .\/build.sh<\/pre>\n<p><strong>Step 4:<\/strong> Configure AWS CLI using steps mentioned <a href=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/cli-chap-getting-started.html#cli-quick-configuration\" target=\"_blank\" rel=\"noopener\">here<\/a>. Once configured, create an AWS role with name as\u00a0<strong>FindAllMoviesRole<\/strong> following the steps mentioned <a href=\"https:\/\/docs.aws.amazon.com\/IAM\/latest\/UserGuide\/id_roles_create_for-user.html\" target=\"_blank\" rel=\"noopener\">here<\/a>\u00a0and verify if it is successfully created:<\/p>\n<pre class=\"brush:java\">$ aws iam get-role --role-name FindAllMoviesRole<\/pre>\n<p>Above command should give the response as shown in a screenshot below:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image151.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83887 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image151.png\" alt=\"RESTful API\" width=\"619\" height=\"265\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image151.png 619w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image151-300x128.png 300w\" sizes=\"(max-width: 619px) 100vw, 619px\" \/><\/a><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><strong>Step 5:<\/strong> Next, create a new Lambda function using the AWS CLI as follows:<\/p>\n<pre class=\"brush:java\">aws lambda create-function --function-name FindAllMovies \\\r\n     --zip-file fileb:\/\/deployment.zip \\\r\n     --runtime go1.x --handler main \\\r\n     --role arn:aws:iam::ACCOUNT_ID:role\/FindAllMoviesRole \\\r\n     --region us-east-1<\/pre>\n<p>Once function is created it will give us the output same as shown in a screenshot below:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image161.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83888\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image161.png\" alt=\"RESTful API\" width=\"820\" height=\"157\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image161.png 926w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image161-300x57.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image161-768x147.png 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><\/p>\n<p><strong>Step 6<\/strong>: Heading back to the AWS Lambda Console, you should see that the function has been created successfully:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image2.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83889 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image2.png\" alt=\"RESTful API\" width=\"485\" height=\"199\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image2.png 485w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image2-300x123.png 300w\" sizes=\"(max-width: 485px) 100vw, 485px\" \/><\/a><\/p>\n<p><strong>Step 7<\/strong>: Create a\u00a0sample\u00a0event with an empty JSON, as the function doesn\u2019t expect any argument, and click on the\u00a0<strong>Test<\/strong>\u00a0button:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image3.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83890 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image3.png\" alt=\"RESTful API\" width=\"480\" height=\"263\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image3.png 480w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image3-300x164.png 300w\" sizes=\"(max-width: 480px) 100vw, 480px\" \/><\/a><\/p>\n<p>You will notice in the previous screenshot that the function returns the expected output in a JSON format.<\/p>\n<p><strong>Step 8:<\/strong> Now that the function has been defined, you need to create a new API Gateway in order to trigger it:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image4.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83891 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image4.png\" alt=\"RESTful API\" width=\"471\" height=\"244\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image4.png 471w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image4-300x155.png 300w\" sizes=\"(max-width: 471px) 100vw, 471px\" \/><\/a><\/p>\n<p><strong>Step 9:<\/strong> Next, from\u00a0the <strong>Actions<\/strong>\u00a0drop-down list, select\u00a0<strong>Create resource<\/strong>\u00a0and name it\u00a0<strong>movies<\/strong>:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image5.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83892 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image5.png\" alt=\"RESTful API\" width=\"486\" height=\"180\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image5.png 486w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image5-300x111.png 300w\" sizes=\"(max-width: 486px) 100vw, 486px\" \/><\/a><\/p>\n<p><strong>Step 10:<\/strong> Expose a <strong>GET<\/strong> method on this\u00a0<strong>\/movies<\/strong>\u00a0resource by clicking on\u00a0<strong>Create Method<\/strong>. Choose\u00a0<strong>Lambda Function<\/strong>\u00a0under the\u00a0<strong>Integration type<\/strong>\u00a0section and select the\u00a0<strong>FindAllMovies<\/strong>\u00a0function:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image6.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83893 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image6.png\" alt=\"RESTful API\" width=\"484\" height=\"301\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image6.png 484w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image6-300x187.png 300w\" sizes=\"(max-width: 484px) 100vw, 484px\" \/><\/a><\/p>\n<p><strong>Step 11:<\/strong> To deploy the API, select\u00a0<strong>Deploy API<\/strong>\u00a0from the\u00a0<strong>Actions<\/strong>\u00a0drop-down list.\u00a0You\u2019ll be prompted to create a new deployment stage:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image7.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83894 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image7.png\" alt=\"RESTful API\" width=\"475\" height=\"301\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image7.png 475w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image7-300x190.png 300w\" sizes=\"(max-width: 475px) 100vw, 475px\" \/><\/a><\/p>\n<p><strong>Step 12:<\/strong> Once the deployment stage is created, an invocation URL will be displayed:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image8.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83895 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image8.png\" alt=\"RESTful API\" width=\"474\" height=\"62\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image8.png 474w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image8-300x39.png 300w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><\/a><\/p>\n<p><strong>Step 13:<\/strong> Point your browser to the URL given or use a modern REST client like Postman or Insomnia. You can go with the <strong>cURL<\/strong> tool as it is installed by default on almost all operating systems:<\/p>\n<pre class=\"brush:java\">curl -sX GET https:\/\/51cxzthvma.execute-api.us-east-1.amazonaws.com\/staging\/movies | jq '.'<\/pre>\n<p>The above command will return a list of movies in a JSON format:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image9.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83896 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image9.png\" alt=\"RESTful API\" width=\"180\" height=\"268\" \/><\/a><\/p>\n<p>When\u00a0calling\u00a0the\u00a0<strong>GET\u00a0<\/strong>endpoint, the request will go through the API Gateway, which will trigger the\u00a0<strong>findAll<\/strong> handler. This returns a response proxied by the API Gateway to the client in a JSON format.<\/p>\n<p>Now that the\u00a0<strong>findAll\u00a0<\/strong>function has been deployed, you can implement a\u00a0<strong>findOne\u00a0<\/strong>function to search for a movie by its ID.<\/p>\n<h2>The GET method with parameters<\/h2>\n<p>The\u00a0<strong>findOne<\/strong> handler\u00a0expects the <strong>APIGatewayProxyRequest <\/strong>argument that contains the event input. Then, it uses the\u00a0<strong>PathParameters\u00a0<\/strong>method to get the movie ID and validate it.<\/p>\n<p>If the ID provided is not a valid number, the\u00a0<strong>Atoi\u00a0<\/strong>method will return an error, and a <strong>500<\/strong> error code will be returned to the client. Otherwise, a movie will be fetched based on the index and returned to the client with a <strong>200 OK<\/strong> status wrapped in\u00a0<strong>APIGatewayProxyResponse<\/strong>:<\/p>\n<pre class=\"brush:java\">...\r\n\r\nfunc findOne(req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {\r\n\r\n\u00a0 id, err := strconv.Atoi(req.PathParameters[\"id\"])\r\n\r\n\u00a0 if err != nil {\r\n\r\n\u00a0\u00a0\u00a0 return events.APIGatewayProxyResponse{\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 StatusCode: 500,\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 Body:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"ID must be a number\",\r\n\r\n\u00a0\u00a0\u00a0 }, nil\r\n\r\n\u00a0 }\r\n\r\n\u00a0 response, err := json.Marshal(movies[id-1])\r\n\r\n\u00a0 if err != nil {\r\n\r\n\u00a0\u00a0\u00a0 return events.APIGatewayProxyResponse{\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 StatusCode: 500,\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 Body:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 err.Error(),\r\n\r\n\u00a0\u00a0\u00a0 }, nil\r\n\r\n\u00a0 }\r\n\r\n\u00a0 return events.APIGatewayProxyResponse{\r\n\r\n\u00a0\u00a0\u00a0 StatusCode: 200,\r\n\r\n\u00a0\u00a0\u00a0 Headers: map[string]string{\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 \"Content-Type\": \"application\/json\",\r\n\r\n\u00a0\u00a0\u00a0 },\r\n\r\n\u00a0\u00a0\u00a0 Body: string(response),\r\n\r\n\u00a0 }, nil\r\n\r\n}\r\n\r\nfunc main() {\r\n\r\n\u00a0 lambda.Start(findOne)\r\n\r\n}<\/pre>\n<p>Similar to the\u00a0<strong>FindAllMovies\u00a0<\/strong>function, create a new Lambda function for searching for a movie:<\/p>\n<pre class=\"brush:java\">aws lambda create-function --function-name FindOneMovie \\\r\n    --zip-file fileb:\/\/deployment.zip \\\r\n    --runtime go1.x --handler main \\\r\n    --role arn:aws:iam::ACCOUNT_ID:role\/FindOneMovieRole \\\r\n    --region us-east-1<\/pre>\n<p>Go back to API Gateway console, create a new resource, expose the <strong>GET\u00a0<\/strong>method, and then link the resource to the <strong>FindOneMovie\u00a0<\/strong>function.\u00a0Note the use of the\u00a0<strong>{id}<\/strong>\u00a0placeholder in the path. The value of\u00a0id\u00a0will be made available via the\u00a0<strong>APIGatewayProxyResponse\u00a0<\/strong>object. The following screenshot depicts this:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image10.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83897 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image10.png\" alt=\"RESTful API\" width=\"425\" height=\"267\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image10.png 425w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image10-300x188.png 300w\" sizes=\"(max-width: 425px) 100vw, 425px\" \/><\/a><\/p>\n<p>Redeploy the API and\u00a0use\u00a0the following <strong>cURL<\/strong> command to test the endpoint:<\/p>\n<pre class=\"brush:java\">curl -sX https:\/\/51cxzthvma.execute-api.us-east-1.amazonaws.com\/staging\/movies\/1 | jq '.'<\/pre>\n<p>The following JSON will be returned:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image11.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83898 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image11.png\" alt=\"RESTful API\" width=\"250\" height=\"97\" \/><\/a><\/p>\n<p>When the API URL is invoked with an ID, the movie corresponding to the ID is returned if it exists.<\/p>\n<h2>The POST method<\/h2>\n<p>Now you know how the <strong>GET<\/strong> method\u00a0works with and without path parameters. The next step is to pass a JSON payload to a Lambda function through the API Gateway. The code is self-explanatory. It converts the request input to a movie structure, adds it to the list of movies, and returns the new list of movies in a JSON format:<\/p>\n<pre class=\"brush:java\">package main\r\n\r\nimport (\r\n  \"encoding\/json\"\r\n  \"strconv\"\r\n  \"github.com\/aws\/aws-lambda-go\/events\"\r\n  \"github.com\/aws\/aws-lambda-go\/lambda\"\r\n)\r\n\r\ntype Movie struct {\r\n  ID int `json:\"id\"`\r\n  Name string `json:\"name\"`\r\n}\r\n\r\nvar movies = []Movie{\r\n  Movie{\r\n    ID: 1,\r\n    Name: \"Avengers\",\r\n  },\r\n ...\r\n}\r\n\r\nfunc insert(req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {\r\n  var movie Movie\r\n  err := json.Unmarshal([]byte(req.Body), &amp;movie)\r\n  if err != nil {\r\n    return events.APIGatewayProxyResponse{\r\n      StatusCode: 400,\r\n      Body: \"Invalid payload\",\r\n    }, nil\r\n  }\r\n\r\n  movies = append(movies, movie)\r\n\r\n  response, err := json.Marshal(movies)\r\n  if err != nil {\r\n    return events.APIGatewayProxyResponse{\r\n      StatusCode: 500,\r\n      Body: err.Error(),\r\n    }, nil\r\n  }\r\n\r\n  return events.APIGatewayProxyResponse{\r\n    StatusCode: 200,\r\n    Headers: map[string]string{\r\n      \"Content-Type\": \"application\/json\",\r\n    },\r\n    Body: string(response),\r\n  }, nil\r\n}\r\n\r\nfunc main() {\r\n  lambda.Start(insert)\r\n}<\/pre>\n<p>Next, create a new Lambda function for\u00a0<strong>InsertMovie<\/strong> with the following command:<\/p>\n<pre class=\"brush:java\">aws lambda create-function --function-name InsertMovie \\\r\n     --zip-file fileb:\/\/deployment.zip \\\r\n     --runtime go1.x --handler main \\\r\n     --role arn:aws:iam::ACCOUNT_ID:role\/InsertMovieRole \\\r\n     --region us-east-1<\/pre>\n<p>Next, create a\u00a0<strong>POST\u00a0<\/strong>method on the\u00a0<strong>\/movies<\/strong>\u00a0resource and link it to the <strong>InsertMovie<\/strong> function:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image12.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83899 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image12.png\" alt=\"RESTful API\" width=\"317\" height=\"196\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image12.png 317w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image12-300x185.png 300w\" sizes=\"(max-width: 317px) 100vw, 317px\" \/><\/a><\/p>\n<p>To test it out, use the following <strong>cURL<\/strong> command with the\u00a0<strong>POST\u00a0<\/strong>verb and the\u00a0<strong>-d<\/strong>\u00a0flag, followed by a JSON string (with the\u00a0id\u00a0and\u00a0name\u00a0attributes):<\/p>\n<pre class=\"brush:java\">curl -sX POST -d '{\"id\":6, \"name\": \"Spiderman:Homecoming\"}' https:\/\/51cxzthvma.execute-api.us-east-1.amazonaws.com\/staging\/movies | jq '.'<\/pre>\n<p>The above command will return the following JSON response:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image13.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83900 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image13.png\" alt=\"RESTful API\" width=\"177\" height=\"252\" \/><\/a><\/p>\n<p>As you can see, the new movie has been inserted successfully. If you test it again, it should work as expected:<\/p>\n<pre class=\"brush:java\">curl -sX POST -d '{\"id\":7, \"name\": \"Iron man\"}' https:\/\/51cxzthvma.execute-api.us-east-1.amazonaws.com\/staging\/movies | jq '.'<\/pre>\n<p>The preceding command will return the following JSON response:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image14.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83901 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image14.png\" alt=\"RESTful API\" width=\"267\" height=\"450\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image14.png 267w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image14-178x300.png 178w\" sizes=\"(max-width: 267px) 100vw, 267px\" \/><\/a><\/p>\n<p>As you can see, it was\u00a0successful\u00a0and the movie was again inserted as expected, but what if you wait few minutes and try to insert a third movie? The following command will be used to execute it again:<\/p>\n<pre class=\"brush:java\">curl -sX POST -d '{\"id\":8, \"name\": \"Captain America\"}' https:\/\/51cxzthvma.execute-api.us-east-1.amazonaws.com\/staging\/movies | jq '.'<\/pre>\n<p>Once again, a new JSON response will be returned:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image15.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83902 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image15.png\" alt=\"RESTful API\" width=\"216\" height=\"364\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image15.png 216w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image15-178x300.png 178w\" sizes=\"(max-width: 216px) 100vw, 216px\" \/><\/a><\/p>\n<p>You will find that the movies with IDs 6 and 7 have been removed; why did this happen?\u00a0 It\u2019s simple. Lambda functions are stateless.<\/p>\n<p>When the\u00a0<strong>InsertMovie <\/strong>function is invoked for the first time (first insert), AWS Lambda creates a container and deploys the function payload to the container. Then, it remains active for a few minutes before it is terminated (<strong>warm start<\/strong>), which explains why the second\u00a0insert passed. In the third insert, the container is already terminated, and hence Lambda creates a new container (<strong>cold start<\/strong>) to handle the insert.<\/p>\n<p>This is why the previous state is lost. The following diagram illustrates the cold\/warm start issue:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image16.png\"><img decoding=\"async\" class=\"aligncenter wp-image-83903 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image16.png\" alt=\"RESTful API\" width=\"397\" height=\"287\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image16.png 397w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/11\/image16-300x217.png 300w\" sizes=\"(max-width: 397px) 100vw, 397px\" \/><\/a><\/p>\n<p>This explains why Lambda\u00a0functions\u00a0should be stateless and why you should not make any assumptions that the state will be preserved from one invocation to the next.<\/p>\n<p>Complete source code is hosted on\u00a0<a href=\"https:\/\/github.com\/arpitaggarwal\/rest-api-go-aws-lambda\" target=\"_blank\" rel=\"noopener\">github<\/a>.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>Published on Java Code Geeks with permission by Arpit Aggarwal, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener\">JCG program<\/a>. See the original article here: <a href=\"https:\/\/aggarwalarpit.wordpress.com\/2018\/11\/22\/build-a-restful-api-in-go-using-aws-lambda\/\" target=\"_blank\" rel=\"noopener\">Build a RESTful API in Go using AWS Lambda<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this post we\u00a0will\u00a0learn to design, build, and deploy a RESTful API in Go using AWS Lambda. Before starting, let me give you a brief introduction about AWS Lambda. What is AWS Lambda? AWS Lambda is a\u00a0serverless compute\u00a0service that runs our code in response to events and automatically manages the underlying compute resources for us. &hellip;<\/p>\n","protected":false},"author":987,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[1669,935],"class_list":["post-83872","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-aws-lambda","tag-go"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Build a RESTful API in Go using AWS Lambda - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn about RESTful API? Check our article explaining how to design, build, and deploy a RESTful API in Go using AWS Lambda.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Build a RESTful API in Go using AWS Lambda - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about RESTful API? Check our article explaining how to design, build, and deploy a RESTful API in Go using AWS Lambda.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/arpit.aggarwal.1989\" \/>\n<meta property=\"article:published_time\" content=\"2018-11-24T13:05:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Arpit Aggarwal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@aggarwalarpit89\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Arpit Aggarwal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/build-restful-api-go-using-aws-lambda.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/build-restful-api-go-using-aws-lambda.html\"},\"author\":{\"name\":\"Arpit Aggarwal\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/3927a00b4d96161bd6325e311a40e98e\"},\"headline\":\"Build a RESTful API in Go using AWS Lambda\",\"datePublished\":\"2018-11-24T13:05:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/build-restful-api-go-using-aws-lambda.html\"},\"wordCount\":1455,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/build-restful-api-go-using-aws-lambda.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"keywords\":[\"AWS lambda\",\"Go\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/build-restful-api-go-using-aws-lambda.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/build-restful-api-go-using-aws-lambda.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/build-restful-api-go-using-aws-lambda.html\",\"name\":\"Build a RESTful API in Go using AWS Lambda - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/build-restful-api-go-using-aws-lambda.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/build-restful-api-go-using-aws-lambda.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2018-11-24T13:05:29+00:00\",\"description\":\"Interested to learn about RESTful API? Check our article explaining how to design, build, and deploy a RESTful API in Go using AWS Lambda.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/build-restful-api-go-using-aws-lambda.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/build-restful-api-go-using-aws-lambda.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/build-restful-api-go-using-aws-lambda.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"java-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/11\\\/build-restful-api-go-using-aws-lambda.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Build a RESTful API in Go using AWS Lambda\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/3927a00b4d96161bd6325e311a40e98e\",\"name\":\"Arpit Aggarwal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a0dc71e538e67766feb7c436ea43f02757eeb1f9446613ae680752be7239a3f6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a0dc71e538e67766feb7c436ea43f02757eeb1f9446613ae680752be7239a3f6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a0dc71e538e67766feb7c436ea43f02757eeb1f9446613ae680752be7239a3f6?s=96&d=mm&r=g\",\"caption\":\"Arpit Aggarwal\"},\"description\":\"Arpit is a Consultant at Xebia India. He has been designing and building J2EE applications since more than 6 years. He is fond of Object Oriented and lover of Functional programming. You can read more of his writings at aggarwalarpit.wordpress.com\",\"sameAs\":[\"https:\\\/\\\/aggarwalarpit.wordpress.com\\\/\",\"https:\\\/\\\/www.facebook.com\\\/arpit.aggarwal.1989\",\"https:\\\/\\\/in.linkedin.com\\\/in\\\/arpitaggarwalxebia\",\"https:\\\/\\\/x.com\\\/aggarwalarpit89\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/arpit-aggarwal\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Build a RESTful API in Go using AWS Lambda - Java Code Geeks","description":"Interested to learn about RESTful API? Check our article explaining how to design, build, and deploy a RESTful API in Go using AWS Lambda.","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:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html","og_locale":"en_US","og_type":"article","og_title":"Build a RESTful API in Go using AWS Lambda - Java Code Geeks","og_description":"Interested to learn about RESTful API? Check our article explaining how to design, build, and deploy a RESTful API in Go using AWS Lambda.","og_url":"https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/arpit.aggarwal.1989","article_published_time":"2018-11-24T13:05:29+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Arpit Aggarwal","twitter_card":"summary_large_image","twitter_creator":"@aggarwalarpit89","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Arpit Aggarwal","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html"},"author":{"name":"Arpit Aggarwal","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/3927a00b4d96161bd6325e311a40e98e"},"headline":"Build a RESTful API in Go using AWS Lambda","datePublished":"2018-11-24T13:05:29+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html"},"wordCount":1455,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","keywords":["AWS lambda","Go"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html","url":"https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html","name":"Build a RESTful API in Go using AWS Lambda - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2018-11-24T13:05:29+00:00","description":"Interested to learn about RESTful API? Check our article explaining how to design, build, and deploy a RESTful API in Go using AWS Lambda.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","width":150,"height":150,"caption":"java-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2018\/11\/build-restful-api-go-using-aws-lambda.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Build a RESTful API in Go using AWS Lambda"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/3927a00b4d96161bd6325e311a40e98e","name":"Arpit Aggarwal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a0dc71e538e67766feb7c436ea43f02757eeb1f9446613ae680752be7239a3f6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a0dc71e538e67766feb7c436ea43f02757eeb1f9446613ae680752be7239a3f6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a0dc71e538e67766feb7c436ea43f02757eeb1f9446613ae680752be7239a3f6?s=96&d=mm&r=g","caption":"Arpit Aggarwal"},"description":"Arpit is a Consultant at Xebia India. He has been designing and building J2EE applications since more than 6 years. He is fond of Object Oriented and lover of Functional programming. You can read more of his writings at aggarwalarpit.wordpress.com","sameAs":["https:\/\/aggarwalarpit.wordpress.com\/","https:\/\/www.facebook.com\/arpit.aggarwal.1989","https:\/\/in.linkedin.com\/in\/arpitaggarwalxebia","https:\/\/x.com\/aggarwalarpit89"],"url":"https:\/\/www.javacodegeeks.com\/author\/arpit-aggarwal"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/83872","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/987"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=83872"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/83872\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=83872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=83872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=83872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}