Skip to content

Commit

Permalink
Update Lambda function code path
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderfanz committed Dec 6, 2023
1 parent 681eed2 commit cd5a7b2
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lambdago.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
aws-region: us-east-1

- name: Upload Zip
run: aws lambda update-function-code --function-name gohtmx --zip-file fileb://main.zip
run: aws lambda update-function-code --function-name gohtmx --zip-file fileb://bin/main.zip
66 changes: 60 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,63 @@
.PHONY: build run
# Both native and cross architecture builds are supported.
# The target architecture is select by setting the ARCH variable.
# When ARCH is undefined it is set to the detected host architecture.
# When ARCH differs from the host architecture a crossbuild will be performed.
ARCHES = amd64 arm64 ppc64le s390x

# BUILDARCH is the host architecture
# ARCH is the target architecture
# we need to keep track of them separately
BUILDARCH ?= $(shell uname -m)

# canonicalized names for host architecture
ifeq ($(BUILDARCH),aarch64)
BUILDARCH=arm64
endif
ifeq ($(BUILDARCH),x86_64)
BUILDARCH=amd64
endif

# unless otherwise set, I am building for my own architecture, i.e. not cross-compiling
ARCH ?= $(BUILDARCH)

# canonicalized names for target architecture
ifeq ($(ARCH),aarch64)
override ARCH=arm64
endif
ifeq ($(ARCH),x86_64)
override ARCH=amd64
endif


build:
@echo "Building Go application..."
@cd src && go build -o main
@echo "Building Go application..."
cd src && GOOS=linux GOARCH=$(ARCH) go build -o ../bin/main main.go

zip:
cd bin && zip -j main.zip main


run:
go run main.go

test:
@echo "No Testing Go application..."

compile:
echo "Compiling for every OS and Platform"
GOOS=linux GOARCH=arm go build -o bin/main-linux-arm main.go
GOOS=linux GOARCH=arm64 go build -o bin/main-linux-arm64 main.go
GOOS=freebsd GOARCH=386 go build -o bin/main-freebsd-386 main.go

clean:
rm -rf bin/*

# .PHONY: build run
# build:
# @echo "Building Go application..."
# @cd src && go build -o main

# run: build
# @echo "Running Go application..."
# @./src/main

run: build
@echo "Running Go application..."
@./src/main
Binary file added bin/main
Binary file not shown.
2 changes: 2 additions & 0 deletions src/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/alexanderfanz/go-htmx-template/src

go 1.21.4

require github.com/aws/aws-lambda-go v1.41.0 // indirect
2 changes: 2 additions & 0 deletions src/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/aws/aws-lambda-go v1.41.0 h1:l/5fyVb6Ud9uYd411xdHZzSf2n86TakxzpvIoz7l+3Y=
github.com/aws/aws-lambda-go v1.41.0/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM=
20 changes: 18 additions & 2 deletions src/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@

package main

import (
"context"
"fmt"
"log"

"github.com/aws/aws-lambda-go/lambda"
)

type MyEvent struct {
Name string `json:"name"`
}

func lambdaHandler(ctx context.Context, event *MyEvent) (*string, error) {
log.Printf("Received event: %v", event)
if event == nil {
return nil, fmt.Errorf("received nil event")
}
message := fmt.Sprintf("Hello %s!", event.Name)
return &message, nil
}

func main() {
log.Println("Starting from main")
lambda.Start(lambdaHandler)
}

0 comments on commit cd5a7b2

Please sign in to comment.