Skip to content

Instantly share code, notes, and snippets.

@toddlers
Created January 6, 2020 16:23
Show Gist options
  • Save toddlers/f6a04b4a8f86efebe6e2a82e7bb49b88 to your computer and use it in GitHub Desktop.
Save toddlers/f6a04b4a8f86efebe6e2a82e7bb49b88 to your computer and use it in GitHub Desktop.
golang-lambda
mkdir helloworld
cd !$
go get github.com/aws/aws-lambda-go/lambda
GOOS=linux go build -o helloworld
aws iam create-role --role-name lambda-basic-execution
--assume-role-policy-document file://lambda-trust-policy.json
aws iam attach-role-policy --role-name lambda-basic-execution
--policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
aws lambda create-function \
--function-name helloworld_go \
--zip-file fileb://helloworld.zip \
--handler helloworld \
--runtime go1.x \
--role "<ROLE_ARN>"
aws lambda invoke \
--function-name helloworld_go \
--invocation-type "RequestResponse" \
response.txt
package main
import "github.com/aws/aws-lambda-go/lambda"
func HandleRequest() (string, error) {
return "Hello from Go !", nil
}
func main() {
lambda.Start(HandleRequest)
}
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment