AWS: Creating a Lambda using GoLang and deploying it using Terraform

preview_player
Показать описание
AWS: Creating a Lambda using GoLang and deploying it using Terraform

Quick tutorial on how to create AWS Lambda using GoLang, compiling and deploying it using Terraform

-----
Topics:
- Create GoLang lambda
- Compile for AWS expected binary
- Create Terraform for your lambda
- Deploy and invoke lambda

-----
Commands used:
terraform init
terraform apply

-----
Code:
package main

import (
"fmt"

)

type MyInput struct {
Action string `json:"action"`
Data string `json:"data"`
}

type MyResponse struct {
StatusCode string `json:"statusCode"`
StatusMessage string `json:"statusMessage"`
}

func handle(event MyInput) (MyResponse, error) {
fmt.Printf("%v\n", event)

return MyResponse{StatusCode: "200", StatusMessage: "Success"}, nil
}

func main() {
lambda.Start(handle)
}

-----
Terraform:
provider "aws" {
region = "us-east-2"
profile = "dev-01"
}

resource "aws_lambda_function" "dev-golambda" {
function_name = "dev-golambda"
handler = "golambdabin"
runtime = "go1.x"
role = "YOUR ARN ROLE HERE"
memory_size = 128
timeout = 10
}

-----

Thank you so much for watching! If you liked, please come back soon for more examples shortly.

In the future I will also add SNS, Elastic Search, Kibana and other examples.

If there is another AWS serverless topic you are interested, please add a comment and I will do my best to show an example using it.

See you soon!

-- Contents of this video --

0:00 Intro
0:31 Create GoLang lambda
1:57 Compile for AWS expected binary
3:00 Create Terraform for your lambda
4:35 Deploy and invoke lambda
Рекомендации по теме
Комментарии
Автор

Seems to be a great video but very difficult to follow due to the extremely small fonts. Why that?

orebelo
Автор

Hi, great video! but I stepped into an issue when I run terraform apply, I get this error:
Error: Plugin error

│ with aws_lambda_function.dev-golambda,
│ on lambda.tf line 6, in resource "aws_lambda_function" "dev-golambda":
│ 6: resource "aws_lambda_function" "dev-golambda" {

│ The plugin returned an unexpected error from rpc error: code = ResourceExhausted desc =
│ grpc: received message larger than max (7281731 vs. 4194304)

Any help?

Thank you in advance!

gianniskiouris-kyparisis
visit shbcf.ru