{"id":3040,"date":"2018-06-01T10:00:38","date_gmt":"2018-06-01T01:00:38","guid":{"rendered":"https:\/\/blog.timecrowd.net\/?p=3040"},"modified":"2018-05-29T16:34:48","modified_gmt":"2018-05-29T07:34:48","slug":"hello-go","status":"publish","type":"post","link":"https:\/\/blog.timecrowd.net\/hello-go\/","title":{"rendered":"Hello, Go! &#8211; AWS Lamba\u3067Go\u3092\u66f8\u304f"},"content":{"rendered":"<p>\u4eca\u5e74\u306f\u3058\u3081\u306bAWS Lambda\u3067Go\u3092\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"https:\/\/aws.amazon.com\/jp\/about-aws\/whats-new\/2018\/01\/aws-lambda-supports-go\/\" target=\"_blank\" rel=\"noopener\">https:\/\/aws.amazon.com\/jp\/about-aws\/whats-new\/2018\/01\/aws-lambda-supports-go\/<\/a><\/p>\n<p>AWS Lambda\u3067\u81ea\u52d5\u5316\u306e\u4ed5\u7d44\u307f\u3092\u4f5c\u308a\u305f\u3044\u3053\u3068\u3082\u3042\u3063\u3066\u3001\u4eca\u56de\u306f\u524d\u3005\u304b\u3089Go\u3067\u95a2\u6570\u3092\u66f8\u3044\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u6700\u8fd1\u5927\u91cf\u306e\u868a\u306b\u60a9\u307e\u3055\u308c\u7761\u7720\u3092\u963b\u5bb3\u3055\u308c\u3066\u3044\u308b\u53f0\u6e7e\u5927\u597d\u304d\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u4e09\u5b85\u3067\u3059\u3002<\/p>\n<p>\u3044\u304d\u306a\u308a\u81ea\u52d5\u5316\u3059\u308b\u305f\u3081\u306e\u30b3\u30fc\u30c9\u3092\u66f8\u3053\u3046\u3068\u601d\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u305d\u3082\u305d\u3082Go\u3067\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u305f\u3053\u3068\u304c\u5168\u304f\u7121\u3044\u306e\u3067\u3001\u307e\u305a\u306fGo\u306b\u89e6\u308c\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<div id=\"toc_container\" class=\"toc_white no_bullets\"><p class=\"toc_title\">\u76ee\u6b21<\/p><ul class=\"toc_list\"><li><a href=\"#i\"><span class=\"toc_number toc_depth_1\">1<\/span> \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a><\/li><li><a href=\"#Hello_World\"><span class=\"toc_number toc_depth_1\">2<\/span> Hello, World<\/a><\/li><li><a href=\"#Hello_World_on_AWS_Lambda\"><span class=\"toc_number toc_depth_1\">3<\/span> Hello, World on AWS Lambda<\/a><\/li><li><a href=\"#i-2\"><span class=\"toc_number toc_depth_1\">4<\/span> \u307e\u3068\u3081<\/a><\/li><\/ul><\/div>\n<h2><span id=\"i\">\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/span><\/h2>\n<p>\u516c\u5f0f\u30b5\u30a4\u30c8\u306b\u306f\u30d0\u30a4\u30ca\u30ea\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u65b9\u6cd5\u304c\u66f8\u304b\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u4eca\u56de\u306fhomebrew\u3092\u4f7f\u3063\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre><code>$ brew install go<\/code><\/pre>\n<p>\u30d0\u30a4\u30ca\u30ea\u304b\u3089\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u65b9\u306f\u4ee5\u4e0b\u306eURL\u304b\u3089\u3069\u3046\u305e\u3002<\/p>\n<p><a href=\"https:\/\/golang.org\/dl\/\" target=\"_blank\" rel=\"noopener\">https:\/\/golang.org\/dl\/<\/a><\/p>\n<pre><code>$ go version\r\ngo version go1.10.2 darwin\/amd64<\/code><\/pre>\n<p>\u6b63\u5e38\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<h2><span id=\"Hello_World\">Hello, World<\/span><\/h2>\n<p>\u3067\u306f\u5b9a\u756a\u306eHello, World\u3092\u51fa\u529b\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u66f8\u3044\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u30ef\u30fc\u30af\u30b9\u30da\u30fc\u30b9\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/p>\n<p>$ mkdir ~\/path\/to\/hello<\/p>\n<p>\u305d\u306e\u4e2d\u3067\u540c\u540d\u306e\u30d5\u30a1\u30a4\u30ebhello.go\u3092\u4f5c\u6210\u3057\u3066\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<pre><code>$ cd ~\/path\/to\/hello\r\n$ vim hello.go<\/code><\/pre>\n<pre><code>package main\r\n\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n  fmt.Printf(\"Hello, World!\\n\")\r\n}\r\n<\/code><\/pre>\n<p>\u30b3\u30fc\u30c9\u3092\u66f8\u304d\u7d42\u3048\u305f\u3089\u30b3\u30de\u30f3\u30c9\u3067\u30d3\u30eb\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<pre><code>$ go build<\/code><\/pre>\n<p>hello\u3068\u3044\u3046\u5b9f\u884c\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u308b\u306e\u3067\u5b9f\u884c\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre><code>$ .\/hello\r\nHello, World!\r\n<\/code><\/pre>\n<p>\u7121\u4e8bHello, World!\u3068\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<h2><span id=\"Hello_World_on_AWS_Lambda\">Hello, World on AWS Lambda<\/span><\/h2>\n<p>\u305b\u3063\u304b\u304f\u306a\u306e\u3067AWS Lambda\u4e0a\u3067\u3082Hello, Go\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u305d\u306e\u307e\u307e\u52d5\u304b\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre><code>$ mkdir \/path\/to\/hello_lambda\r\n$ vim hello_lambda.go\r\n<\/code><\/pre>\n<pre><code>package main\r\n\r\nimport (\r\n  \"fmt\"\r\n  \"context\"\r\n  \"github.com\/aws\/aws-lambda-go\/lambda\"\r\n)\r\n\r\ntype MyEvent struct {\r\n  Name string `json:\"name\"`\r\n}\r\n\r\nfunc HandleRequest(ctx context.Context, name MyEvent) (string, error) {\r\n  return fmt.Sprintf(\"Hello %s!\", name.Name), nil\r\n}\r\n\r\nfunc main() {\r\n  lambda.Start(HandleRequest)\r\n}\r\n<\/code><\/pre>\n<p>\u30b3\u30fc\u30c9\u3092\u30d3\u30eb\u30c9\u3057\u3066zip\u30d5\u30a1\u30a4\u30eb\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre><code>$ go build\r\n$ zip handler.zip .\/hello_lambda<\/code><\/pre>\n<p>\u305d\u308c\u304b\u3089AWS Lambda\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u307e\u3059\u3002\u95a2\u6570\u30d1\u30c3\u30b1\u30fc\u30b8\u3088\u308azip\u30d5\u30a1\u30a4\u30eb\u3092\u9078\u629e\u3057\u3001\u30cf\u30f3\u30c9\u30e9\u540d\u3092\u5165\u529b\u3057\u3066\u3001\u6700\u5f8c\u306b\u300c\u4fdd\u5b58\u300d\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-3044\" src=\"https:\/\/blog.timecrowd.net\/wp-content\/uploads\/2018\/05\/Screen_Shot_2018-05-25_at_9_58_23.png\" alt=\"\" width=\"2626\" height=\"888\" srcset=\"https:\/\/blog.timecrowd.net\/wp-content\/uploads\/2018\/05\/Screen_Shot_2018-05-25_at_9_58_23.png 2626w, https:\/\/blog.timecrowd.net\/wp-content\/uploads\/2018\/05\/Screen_Shot_2018-05-25_at_9_58_23-768x260.png 768w\" sizes=\"(max-width: 2626px) 100vw, 2626px\" \/><\/p>\n<p>\u3067\u306f\u3001\u3055\u3063\u305d\u304f\u5b9f\u969b\u306b\u52d5\u304f\u306e\u304b\u30c6\u30b9\u30c8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u306f\u300c\u30c6\u30b9\u30c8\u30a4\u30d9\u30f3\u30c8\u306e\u8a2d\u5b9a\u300d\u3067\u30c6\u30b9\u30c8\u30a4\u30d9\u30f3\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-3045\" src=\"https:\/\/blog.timecrowd.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-25-at-10.02.34.png\" alt=\"\" width=\"1698\" height=\"968\" srcset=\"https:\/\/blog.timecrowd.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-25-at-10.02.34.png 1698w, https:\/\/blog.timecrowd.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-25-at-10.02.34-768x438.png 768w\" sizes=\"(max-width: 1698px) 100vw, 1698px\" \/><\/p>\n<p>\u30c6\u30b9\u30c8\u30a4\u30d9\u30f3\u30c8\u3092\u4f5c\u6210\u3067\u304d\u305f\u3089\u3001\u300c\u30c6\u30b9\u30c8\u300d\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-3046\" src=\"https:\/\/blog.timecrowd.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-25-at-10.07.33.png\" alt=\"\" width=\"2608\" height=\"520\" srcset=\"https:\/\/blog.timecrowd.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-25-at-10.07.33.png 2608w, https:\/\/blog.timecrowd.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-25-at-10.07.33-768x153.png 768w\" sizes=\"(max-width: 2608px) 100vw, 2608px\" \/><\/p>\n<p>\u5931\u6557\u3057\u3066\u3057\u307e\u3044\u307e\u3057\u305f&#8230;<\/p>\n<p>\u3069\u3046\u3084\u3089Mac\u3067build\u3057\u3066AWS Lambda\u3067\u52d5\u304b\u3059\u306b\u306fOS\u3092\u6307\u5b9a\u3057\u3066\u30d3\u30eb\u30c9\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/blog.rowanudell.com\/aws-sam-local-error-with-golang\/\" target=\"_blank\" rel=\"noopener\">https:\/\/blog.rowanudell.com\/aws-sam-local-error-with-golang\/<\/a><\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u65e9\u901f\u30d3\u30eb\u30c9\u3057\u76f4\u3057\u3066\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre><code>$ GOOS=linux go build .\/hello_lambda.go<\/code><\/pre>\n<p>\u518d\u5ea6\u30c6\u30b9\u30c8\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-3053\" src=\"https:\/\/blog.timecrowd.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-25-at-10.48.47.png\" alt=\"\" width=\"2598\" height=\"398\" srcset=\"https:\/\/blog.timecrowd.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-25-at-10.48.47.png 2598w, https:\/\/blog.timecrowd.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-25-at-10.48.47-768x118.png 768w\" sizes=\"(max-width: 2598px) 100vw, 2598px\" \/><\/p>\n<p>\u7121\u4e8b\u6210\u529f\u3057\u307e\u3057\u305f\u3002<\/p>\n<h2><span id=\"i-2\">\u307e\u3068\u3081<\/span><\/h2>\n<p>\u4eca\u56de\u306f\u521d\u3081\u3066\u306eGo\u3001\u521d\u3081\u3066\u306eAWS Lambda\u3068\u3044\u3046\u3053\u3068\u3067\u8d85\u521d\u6b69\u7684\u306a\u3053\u3068\u3092\u8a66\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u3053\u308c\u304b\u3089Go\u3092\u4f7f\u3044\u3064\u3064\u958b\u767a\u4f5c\u696d\u3067\u5b9a\u578b\u5316\u3057\u305f\u4f5c\u696d\u3092\u81ea\u52d5\u5316\u3059\u308b\u306e\u306bAWS Lambda\u3092\u5229\u7528\u3057\u3066\u307f\u305f\u3044\u306a\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"\u4eca\u5e74\u306f\u3058\u3081\u306bAWS Lambda\u3067Go\u3092\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002 https:\/\/aws.amazon.com\/jp\/about-a&#8230;","protected":false},"author":5,"featured_media":3056,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"cybocfi_hide_featured_image":""},"categories":[5],"tags":[12],"_links":{"self":[{"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/posts\/3040"}],"collection":[{"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/comments?post=3040"}],"version-history":[{"count":14,"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/posts\/3040\/revisions"}],"predecessor-version":[{"id":3062,"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/posts\/3040\/revisions\/3062"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/media\/3056"}],"wp:attachment":[{"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/media?parent=3040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/categories?post=3040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/tags?post=3040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}