Skip to content
This repository was archived by the owner on Oct 4, 2019. It is now read-only.

Commit 8b186ef

Browse files
author
Frank Cash
committed
Basic TF set-up
1 parent d5243e9 commit 8b186ef

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@
1212

1313
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
1414
.glide/
15+
16+
.DS_Store
17+
.terraform
18+
19+
# Ignore binary and zip file that we build
20+
function/main
21+
*.zip
22+
23+
*.tfstate

REAMDE.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# go-lambda-ping
2+
3+
A simple program that will build the infrastructure to ping a website.
4+
5+
## Building the Zip
6+
7+
In the `function` directory run `make release` to generate the binary and then zip it.
8+
9+
## Deploying the Lambda
10+
11+
1. Run `terraform init` to initialize the terraform repository.
12+
13+
2. Then run `terraform plan` to create the execution plan.
14+
15+
3. Finally, `terraform apply` to apply the changes (run the execution plan).
16+
17+
18+
## Trigger the Lambda
19+
```
20+
aws lambda invoke \
21+
--invocation-type RequestResponse \
22+
--function-name demo_lambda \
23+
--region us-east-1 \
24+
--log-type Tail \
25+
--payload '{"key1":"value1", "key2":"value2", "key3":"value3"}' \
26+
outputfile.txt
27+
```

function/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
compile:
2+
GOOS=linux go build -o main
3+
4+
compress:
5+
zip function.zip main
6+
7+
release: compile \
8+
compress

function/function.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package main
2+
3+
import (
4+
"github.com/aws/aws-lambda-go/lambda"
5+
)
6+
7+
func hello() (string, error) {
8+
return "Hello ƛ!", nil
9+
}
10+
11+
func main() {
12+
// Make the handler available for Remote Procedure Call by AWS Lambda
13+
lambda.Start(hello)
14+
}

main.tf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
provider "aws" {
2+
region = "us-east-1"
3+
}
4+
5+
6+
resource "aws_iam_role" "lambda_exec_role" {
7+
name = "lambda_exec_role"
8+
assume_role_policy = <<EOF
9+
{
10+
"Version": "2012-10-17",
11+
"Statement": [
12+
{
13+
"Action": "sts:AssumeRole",
14+
"Principal": {
15+
"Service": "lambda.amazonaws.com"
16+
},
17+
"Effect": "Allow",
18+
"Sid": ""
19+
}
20+
]
21+
}
22+
EOF
23+
}
24+
25+
resource "aws_lambda_function" "demo_lambda" {
26+
function_name = "demo_lambda"
27+
handler = "main"
28+
runtime = "go1.x"
29+
filename = "./function/function.zip"
30+
source_code_hash = "${base64sha256(file("./function/function.zip"))}"
31+
role = "${aws_iam_role.lambda_exec_role.arn}"
32+
}
33+

0 commit comments

Comments
 (0)