Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use AWS Lambda Web Adapter in golang app #912

Open
Fujita-Naoyuki opened this issue May 4, 2024 · 0 comments
Open

How to use AWS Lambda Web Adapter in golang app #912

Fujita-Naoyuki opened this issue May 4, 2024 · 0 comments

Comments

@Fujita-Naoyuki
Copy link

Summary

newrelic cannot be used with AWS Lambda with the following configuration

Desired Behaviour

newrelic is available and information can be referenced on APM

Possible Solution

  • Best solution:
    A library will be created to work with AWS Lambda Web Adapter like nrlambda
  • Another solution:
    Documents related to settings for operation using the newrelic.NewApplication method will be published.

Additional context

Sample: doesn't work

  • main.go
package main

import (
	"fmt"
	"log"
	"net/http"
	"os"

	"github.com/newrelic/go-agent/v3/integrations/logcontext-v2/logWriter"

	"github.com/newrelic/go-agent/v3/newrelic"
)

var app *newrelic.Application
var writer logWriter.LogWriter
var logger *log.Logger

func usersHandler(rw http.ResponseWriter, req *http.Request) {
	txn := app.StartTransaction("usersHandler")
	defer txn.End()
	fmt.Fprintf(rw, "Hello, World")
	logger.Printf("receive hello world request")
}

func main() {
	app, _ = newrelic.NewApplication(
		newrelic.ConfigAppName("newrelic-sample"),
		newrelic.ConfigLicense("mykey"),
		newrelic.ConfigAppLogForwardingEnabled(true),
	)
	writer = logWriter.New(os.Stdout, app)
	logger = log.New(&writer, "", log.Default().Flags())
	logger.Printf("cold start")

	http.HandleFunc(newrelic.WrapHandleFunc(app, "/", usersHandler))

	http.ListenAndServe(":8000", nil)
}
  • Dockerfile
# build
FROM golang:1.21 as build
WORKDIR /helloworld
COPY go.mod go.sum ./
COPY main.go .
RUN GOOS=linux CGO_ENABLED=0  go build -o main main.go

# Copy artifacts to a clean image
FROM alpine:3.9
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.8.3 /lambda-adapter /opt/extensions/lambda-adapter
COPY --from=build /helloworld/main /main
ENV PORT=8000
EXPOSE 8000
ENTRYPOINT [ "/main" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant