@@ -15,10 +15,6 @@ import (
1515 " github.com/akrylysov/algnhsa"
1616)
1717
18- func indexHandler (w http .ResponseWriter , r *http .Request ) {
19- w.Write ([]byte (" index" ))
20- }
21-
2218func addHandler (w http .ResponseWriter , r *http .Request ) {
2319 f , _ := strconv.Atoi (r.FormValue (" first" ))
2420 s , _ := strconv.Atoi (r.FormValue (" second" ))
@@ -27,14 +23,13 @@ func addHandler(w http.ResponseWriter, r *http.Request) {
2723}
2824
2925func contextHandler (w http .ResponseWriter , r *http .Request ) {
30- proxyReq , ok := algnhsa.ProxyRequestFromContext (r.Context ())
26+ lambdaEvent , ok := algnhsa.APIGatewayV2RequestFromContext (r.Context ())
3127 if ok {
32- fmt.Fprint (w, proxyReq .RequestContext .AccountID )
28+ fmt.Fprint (w, lambdaEvent .RequestContext .AccountID )
3329 }
3430}
3531
3632func main () {
37- http.HandleFunc (" /" , indexHandler)
3833 http.HandleFunc (" /add" , addHandler)
3934 http.HandleFunc (" /context" , contextHandler)
4035 algnhsa.ListenAndServe (http.DefaultServeMux , nil )
@@ -56,26 +51,48 @@ import (
5651func main () {
5752 r := chi.NewRouter ()
5853 r.Get (" /" , func (w http.ResponseWriter , r *http.Request ) {
59- w.Write ([]byte (" index " ))
54+ w.Write ([]byte (" hi " ))
6055 })
6156 algnhsa.ListenAndServe (r, nil )
6257}
6358```
6459
65- ## Setting up API Gateway
60+ ## Deployment
61+
62+ First, build your Go application for Linux and zip it:
63+
64+ ``` bash
65+ GOOS=linux GOARCH=amd64 go build -o handler
66+ zip handler.zip handler
67+ ```
68+
69+ AWS provides plenty of ways to expose a Lambda function to the internet.
70+
71+ ### Lambda Function URL
72+
73+ This is the easier way to deploy your Lambda function as an HTTP endpoint.
74+ It only requires going to the "Function URL" section of the Lambda function configuration and clicking "Configure Function URL".
75+
76+ ### API Gateway
77+
78+ #### HTTP API
79+
80+ 1 . Create a new HTTP API.
81+
82+ 2 . Configure a catch-all ` $default ` route.
83+
84+ #### REST API
6685
67861 . Create a new REST API.
6887
69882 . In the "Resources" section create a new ` ANY ` method to handle requests to ` / ` (check "Use Lambda Proxy Integration").
7089
71- ![ API Gateway index] ( https://akrylysov.github.io/algnhsa/apigateway-index.png )
72-
73903 . Add a catch-all ` {proxy+} ` resource to handle requests to every other path (check "Configure as proxy resource").
7491
75- ![ API Gateway catch-all] ( https://akrylysov.github.io/algnhsa/apigateway-catchall.png )
76-
77- ## Setting up ALB
92+ ### ALB
7893
79941 . Create a new ALB and point it to your Lambda function.
8095
81- 2 . In the target group settings enable "Multi value headers".
96+ 2 . In the target group settings in the "Attributes" section enable "Multi value headers".
97+
98+ [ AWS Documentation] ( https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html )
0 commit comments