Skip to content

Instantly share code, notes, and snippets.

@apoorvmote
Created February 23, 2021 05:57
Show Gist options
  • Save apoorvmote/fa8fe94abf1918a4ad35184ff476f6ad to your computer and use it in GitHub Desktop.
Save apoorvmote/fa8fe94abf1918a4ad35184ff476f6ad to your computer and use it in GitHub Desktop.
import { Code, Function, Runtime } from '@aws-cdk/aws-lambda';
import * as cdk from '@aws-cdk/core';
export class GoLambdaStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// The code that defines your stack goes here
new Function(this, 'goLambda', {
runtime: Runtime.GO_1_X,
handler: 'main',
code: Code.fromAsset(`${__dirname}/../lambda-fns/hello-world/`, {
bundling: {
image: Runtime.GO_1_X.bundlingDockerImage,
user: 'root',
command: [
'bash', '-c', [
'cd /asset-input',
'go build -o main main.go',
'mv /asset-input/main /asset-output/'
].join(' && ')
]
}
})
})
}
}
package main
import (
"github.com/aws/aws-lambda-go/lambda"
)
func main() {
lambda.Start(handleRequest)
}
func handleRequest() (string, error) {
return "hello from golang", nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment