- #create a role from cli for the lambda
-
$ aws iam create-role --role-name go-lambda-ex --assume-role-policy-document ' {"Version": "2012-10-17","Statement":[{"Effect": "Allow", "Principal":"{"Service":"lambda.amazonaws.com"}, "Action": "sts:AssumeRole"}]}'
-
alternatively you can add this json policy part to a file trust-policy.json and link the file with command as below (ensure you run the command from the same path as file):
-
$ aws iam create-role --role-name lambda-ex --assume-role-policy-document file://trust-policy.json
-
next, run the following command to setup the lmbda role arn $ aws iam attach-role-policy --role-name lambda-ex --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
-
build your main.go file $ go build main.go
-
zip the main executable $ zip function.zip main
-
create the lambda by attaching the zip file $ aws lambda create-function --function-name go-lambda-function
--zip-file fileb://function-zip --handler main --runtime go1.x
--role arn:aws:iam::xxxxxx:role/lambda-ex -
invoke the lambda function by running the comman below: $ aws lambda invoke --function-name go-lambda-function --cli-binary-format raw-in-base64-out --payload '{"What is your name": "Foster Kojo", "How old are you?": 33}' output.txt
Pointers Concurrency Goroutines mutex Structs and Struct methods