Skip to content

Commit 7f40f45

Browse files
committed
Version 1.0.0
1 parent 4c6f785 commit 7f40f45

22 files changed

Lines changed: 1210 additions & 818 deletions

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
language: go
22
go:
3-
- "1.11.x"
3+
- "1.18.x"
44
- "1.x"

CHANGELOG.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
# Changelog
22

3-
## [0.12.1] - 2019-09-26
3+
## [1.0.0] - 2023-03-02
4+
### Fixed
5+
- API Gateway V2: Fixed response header support.
6+
- API Gateway V2: Fixed handling request cookies.
7+
- API Gateway V2: Fixed multi-value query parameters.
8+
- ALB: Fixed double escaping of query parameters.
9+
10+
### Changed
11+
- `RequestTypeAPIGateway` renamed to `RequestTypeAPIGatewayV1`.
12+
- `ProxyRequestFromContext` renamed to `APIGatewayV1RequestFromContext`.
13+
- `APIGatewayV2HTTPRequestFromContext` renamed to `APIGatewayV2RequestFromContext`.
14+
- `TargetGroupRequestFromContext` renamed to `ALBRequestFromContext`.
15+
- Improved unit tests.
16+
- Go 1.18 is the minimum supported version now.
17+
18+
## [0.13.0] - 2022-01-08
419
### Added
5-
- Fixed compatibility with Go versions older than 1.13.
20+
- API Gateway V2 support (@a-h).
21+
22+
## [0.12.1] - 2019-09-26
23+
### Fixed
24+
- Compatibility with Go versions older than 1.13.
625

726
## [0.12.0] - 2019-09-26
827
### Added
@@ -16,7 +35,7 @@
1635
### Changed
1736
- Set RequestURI on request (@RossHammer).
1837
- Unescape Path (@RossHammer).
19-
- Multi-value header support implemented using APIGatewayProxyResponse.MultiValueHeaders.
38+
- Multi-value header support implemented using `APIGatewayProxyResponse.MultiValueHeaders`.
2039

2140
## [0.9] - 2018-12-10
2241
### Added

README.md

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
2218
func 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

2925
func 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

3632
func 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 (
5651
func 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

6786
1. Create a new REST API.
6887

6988
2. 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-
7390
3. 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

7994
1. 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)

adapter.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package algnhsa
33
import (
44
"context"
55
"encoding/json"
6+
"fmt"
67
"net/http"
78
"net/http/httptest"
89

@@ -21,10 +22,16 @@ func (handler lambdaHandler) Invoke(ctx context.Context, payload []byte) ([]byte
2122
if err != nil {
2223
return nil, err
2324
}
25+
if handler.opts.DebugLog {
26+
fmt.Printf("Response: %+v", resp)
27+
}
2428
return json.Marshal(resp)
2529
}
2630

2731
func (handler lambdaHandler) handleEvent(ctx context.Context, payload []byte) (lambdaResponse, error) {
32+
if handler.opts.DebugLog {
33+
fmt.Printf("Request: %s", payload)
34+
}
2835
eventReq, err := newLambdaRequest(ctx, payload, handler.opts)
2936
if err != nil {
3037
return lambdaResponse{}, err
@@ -35,7 +42,7 @@ func (handler lambdaHandler) handleEvent(ctx context.Context, payload []byte) (l
3542
}
3643
w := httptest.NewRecorder()
3744
handler.httpHandler.ServeHTTP(w, r)
38-
return newLambdaResponse(w, handler.opts.binaryContentTypeMap)
45+
return newLambdaResponse(w, handler.opts.binaryContentTypeMap, eventReq.requestType)
3946
}
4047

4148
// ListenAndServe starts the AWS Lambda runtime (aws-lambda-go lambda.Start) with a given handler.

0 commit comments

Comments
 (0)