This repository was archived by the owner on Oct 4, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +91
-0
lines changed Expand file tree Collapse file tree 5 files changed +91
-0
lines changed Original file line number Diff line number Diff line change 12
12
13
13
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
14
14
.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
Original file line number Diff line number Diff line change
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
+ ```
Original file line number Diff line number Diff line change
1
+ compile :
2
+ GOOS=linux go build -o main
3
+
4
+ compress :
5
+ zip function.zip main
6
+
7
+ release : compile \
8
+ compress
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments