Skip to content

Commit 92a9843

Browse files
committed
2 parents e31c9a1 + c6725b7 commit 92a9843

36 files changed

+314
-50
lines changed

.github/workflows/reviewdog.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: reviewdog
2+
on:
3+
pull_request:
4+
5+
jobs:
6+
test:
7+
name: lint
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Check out code into the Go module directory
11+
uses: actions/checkout@v2
12+
13+
- name: golangci-lint
14+
uses: reviewdog/action-golangci-lint@v1
15+
with:
16+
level: warning
17+
reporter: github-pr-review

.github/workflows/tests.yml

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
11
name: tests
2-
on:
2+
on:
33
push:
44
pull_request:
55

66
jobs:
7-
87
test:
9-
name: run tests with code coverage
8+
name: run tests with code coverage
109
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
go:
13+
- "1.16"
14+
- "1.15"
15+
- "1.14"
16+
- "1.13"
17+
1118
steps:
12-
- name: Set up Go 1.13
19+
- name: Set up Go ${{ matrix.go }}
1320
uses: actions/setup-go@v1
1421
with:
15-
go-version: 1.13
22+
go-version: ${{ matrix.go }}
1623
id: go
1724

1825
- name: Check out code into the Go module directory
1926
uses: actions/checkout@v1
2027

2128
- name: go test
2229
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
23-
24-
- name: Upload coverage to Codecov
30+
31+
- name: Upload coverage to Codecov
2532
uses: codecov/codecov-action@v1
33+
if: matrix.go == '1.16'
2634
with:
27-
file: ./coverage.txt
35+
file: ./coverage.txt

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
[![tests][1]][2]
44
[![build-lambda-zip][3]][4]
5-
[![GoDoc][5]][6]
5+
[![Go Reference][5]][6]
66
[![GoCard][7]][8]
77
[![codecov][9]][10]
88

99
[1]: https://github.com/aws/aws-lambda-go/workflows/tests/badge.svg
1010
[2]: https://github.com/aws/aws-lambda-go/actions?query=workflow%3Atests
1111
[3]: https://github.com/aws/aws-lambda-go/workflows/go%20get%20build-lambda-zip/badge.svg
1212
[4]: https://github.com/aws/aws-lambda-go/actions?query=workflow%3A%22go+get+build-lambda-zip%22
13-
[5]: https://godoc.org/github.com/aws/aws-lambda-go?status.svg
14-
[6]: https://godoc.org/github.com/aws/aws-lambda-go
13+
[5]: https://pkg.go.dev/badge/github.com/aws/aws-lambda-go.svg
14+
[6]: https://pkg.go.dev/github.com/aws/aws-lambda-go
1515
[7]: https://goreportcard.com/badge/github.com/aws/aws-lambda-go
1616
[8]: https://goreportcard.com/report/github.com/aws/aws-lambda-go
1717
[9]: https://codecov.io/gh/aws/aws-lambda-go/branch/master/graph/badge.svg

events/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Overview
22

3-
[![GoDoc](https://godoc.org/github.com/aws/aws-lambda-go/events?status.svg)](https://godoc.org/github.com/aws/aws-lambda-go/events)
3+
[![Go Reference](https://pkg.go.dev/badge/github.com/aws/aws-lambda-go/events.svg)](https://pkg.go.dev/github.com/aws/aws-lambda-go/events)
44

55
This package provides input types for Lambda functions that process AWS events.
66

@@ -12,6 +12,8 @@ This package provides input types for Lambda functions that process AWS events.
1212

1313
[AppSync](README_AppSync.md)
1414

15+
[ClientVPN Connection Handler](README_ClientVPN.md)
16+
1517
[CloudFormation Events](../cfn/README.md)
1618

1719
[CloudWatch Events](README_CloudWatch_Events.md)

events/README_ALBTargetGroupEvents.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-funct
66

77
# Sample Function
88

9-
The following is a sample class and Lambda function that receives an ALB Target Group event as an input, writes some of the incoming data to CloudWatch Logs, and responds with a 200 status and the same body as the request. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
9+
The following is a sample class and Lambda function that receives an ALB Target Group event as an input, writes some of the incoming data to CloudWatch Logs, and responds with a 200 status and the same body as the request. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
1010

1111
```go
1212

events/README_ApiGatewayEvent.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ API Gateway events consist of a request that was routed to a Lambda function by
44

55
# Sample Function
66

7-
The following is a sample class and Lambda function that receives Amazon API Gateway event record data as an input, writes some of the record data to CloudWatch Logs, and responds with a 200 status and the same body as the request. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
7+
The following is a sample class and Lambda function that receives Amazon API Gateway event record data as an input, writes some of the record data to CloudWatch Logs, and responds with a 200 status and the same body as the request. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
88

99
```go
1010

events/README_AutoScaling.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sample Function
22

3-
The following is a sample Lambda function that receives an Auto Scaling event as an input and logs the EC2 instance ID to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
3+
The following is a sample Lambda function that receives an Auto Scaling event as an input and logs the EC2 instance ID to CloudWatch Logs. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
44

55
```go
66
import (

events/README_ClientVPN.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Sample Function
2+
3+
The following is a sample Lambda function that receives a Client VPN connection handler request as an input and then validates the IP address input and checks whether the connection source IP is on the allowed list defined as a map inside the function. If the source IP matches an allowed IP address it allows the access, otherwise an error message is presented to the user. Debug logs are generated to CloudWatch Logs. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
4+
5+
```go
6+
import (
7+
"fmt"
8+
"log"
9+
"net"
10+
11+
"encoding/json"
12+
13+
"github.com/aws/aws-lambda-go/events"
14+
"github.com/aws/aws-lambda-go/lambda"
15+
)
16+
17+
var (
18+
AllowedIPs = map[string]bool{
19+
"10.11.12.13": true,
20+
}
21+
)
22+
23+
func handler(request events.ClientVPNConnectionHandlerRequest) (events.ClientVPNConnectionHandlerResponse, error) {
24+
requestJson, _ := json.MarshalIndent(request, "", " ")
25+
log.Printf("REQUEST: %s", requestJson)
26+
27+
sourceIP := request.PublicIP
28+
if net.ParseIP(sourceIP) == nil {
29+
return events.ClientVPNConnectionHandlerResponse{}, fmt.Errorf("Invalid parameter PublicIP passed in request: %q", sourceIP)
30+
}
31+
32+
log.Printf("SOURCE IP: %q", sourceIP)
33+
34+
if allowed, ok := AllowedIPs[sourceIP]; ok && allowed {
35+
log.Printf("Allowing access from: %q", sourceIP)
36+
return events.ClientVPNConnectionHandlerResponse{
37+
Allow: true,
38+
ErrorMsgOnFailedPostureCompliance: "",
39+
PostureComplianceStatuses: []string{},
40+
SchemaVersion: "v1",
41+
}, nil
42+
}
43+
44+
log.Printf("Blocking access from: %q", sourceIP)
45+
return events.ClientVPNConnectionHandlerResponse{
46+
Allow: false,
47+
ErrorMsgOnFailedPostureCompliance: "You're trying to connect from an IP address that is not allowed.",
48+
PostureComplianceStatuses: []string{"BlockedSourceIP"},
49+
SchemaVersion: "v1",
50+
}, nil
51+
}
52+
53+
func main() {
54+
lambda.Start(handler)
55+
}
56+
```

events/README_Cognito.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sample Function
22

3-
The following is a sample Lambda function that receives Amazon Cognito Sync event record data as an input and writes some of the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
3+
The following is a sample Lambda function that receives Amazon Cognito Sync event record data as an input and writes some of the record data to CloudWatch Logs. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
44

55
```go
66

events/README_Cognito_UserPools_PostConfirmation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sample Function
22

3-
The following is a sample Lambda function that receives Amazon Cognito User Pools post-confirmation event as an input and writes some of the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
3+
The following is a sample Lambda function that receives Amazon Cognito User Pools post-confirmation event as an input and writes some of the record data to CloudWatch Logs. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
44

55
Please see instructions for setting up the Cognito triggers at https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html .
66

events/README_Cognito_UserPools_PreAuthentication.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sample Function
22

3-
The following is a sample Lambda function that receives Amazon Cognito User Pools pre-authentication event as an input and writes some of the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
3+
The following is a sample Lambda function that receives Amazon Cognito User Pools pre-authentication event as an input and writes some of the record data to CloudWatch Logs. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
44

55
Please see instructions for setting up the Cognito triggers at https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html .
66

events/README_Cognito_UserPools_PreSignup.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sample Function
22

3-
The following is a sample Lambda function that receives Amazon Cognito User Pools pre-signup event as an input and writes some of the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
3+
The following is a sample Lambda function that receives Amazon Cognito User Pools pre-signup event as an input and writes some of the record data to CloudWatch Logs. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
44

55
Please see instructions for setting up the Cognito triggers at https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html .
66

events/README_Cognito_UserPools_PreTokenGen.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sample Function
22

3-
The following is a sample Lambda function that receives Amazon Cognito User Pools pre-token-gen event as an input and writes some of the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
3+
The following is a sample Lambda function that receives Amazon Cognito User Pools pre-token-gen event as an input and writes some of the record data to CloudWatch Logs. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
44

55
Please see instructions for setting up the Cognito triggers at https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html .
66

events/README_Config.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sample Function
22

3-
The following is a sample Lambda function that receives Amazon Config event record data as an input and writes some of the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
3+
The following is a sample Lambda function that receives Amazon Config event record data as an input and writes some of the record data to CloudWatch Logs. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
44

55
```go
66

events/README_Connect.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sample Function
22

3-
The following is a sample Lambda function that receives an Amazon Connect event as an input and writes some of the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
3+
The following is a sample Lambda function that receives an Amazon Connect event as an input and writes some of the record data to CloudWatch Logs. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
44

55
```go
66
package main

events/README_Kinesis.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sample Function
22

3-
The following is a sample class and Lambda function that receives Amazon Kinesis event record data as an input and writes some of the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
3+
The following is a sample class and Lambda function that receives Amazon Kinesis event record data as an input and writes some of the record data to CloudWatch Logs. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
44

55
```go
66

events/README_Lex.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Sample Function
33

4-
The following is a sample class and Lambda function that receives Amazon Lex event data as input, writes some of the record data to CloudWatch Logs, and responds back to Lex. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
4+
The following is a sample class and Lambda function that receives Amazon Lex event data as input, writes some of the record data to CloudWatch Logs, and responds back to Lex. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
55

66
```go
77
import (

events/README_S3.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sample Function
22

3-
The following is a sample class and Lambda function that receives Amazon S3 event record data as an input and writes some of the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
3+
The following is a sample class and Lambda function that receives Amazon S3 event record data as an input and writes some of the record data to CloudWatch Logs. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
44

55
```go
66

events/README_S3_Batch_Job.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sample Function
22

3-
The following is a sample class and Lambda function that receives Amazon S3 event record data as an input and writes some of the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
3+
The following is a sample class and Lambda function that receives Amazon S3 event record data as an input and writes some of the record data to CloudWatch Logs. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
44

55
```go
66

events/README_SES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Sample Function
33

4-
The following is a sample class and Lambda function that receives Amazon SES event message data as input, writes some of the message data to CloudWatch Logs, and responds with a 200 status and the same body as the request. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
4+
The following is a sample class and Lambda function that receives Amazon SES event message data as input, writes some of the message data to CloudWatch Logs, and responds with a 200 status and the same body as the request. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
55

66
```go
77
package main

events/README_SNS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Sample Function
33

4-
The following is a sample class and Lambda function that receives Amazon SNS event record data as input, writes some of the record data to CloudWatch Logs, and responds with a 200 status and the same body as the request. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
4+
The following is a sample class and Lambda function that receives Amazon SNS event record data as input, writes some of the record data to CloudWatch Logs, and responds with a 200 status and the same body as the request. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
55

66
```go
77
import (

events/README_SQS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Sample Function
33

4-
The following is a sample class and Lambda function that receives Amazon SQS event message data as input, writes some of the message data to CloudWatch Logs, and responds with a 200 status and the same body as the request. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
4+
The following is a sample class and Lambda function that receives Amazon SQS event message data as input, writes some of the message data to CloudWatch Logs, and responds with a 200 status and the same body as the request. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
55

66
```go
77
package main

events/activemq.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
3+
package events
4+
5+
type ActiveMQEvent struct {
6+
EventSource string `json:"eventSource"`
7+
EventSourceARN string `json:"eventSourceArn"`
8+
Messages []ActiveMQMessage `json:"messages"`
9+
}
10+
11+
type ActiveMQMessage struct {
12+
MessageID string `json:"messageID"`
13+
MessageType string `json:"messageType"`
14+
Timestamp int64 `json:"timestamp"`
15+
DeliveryMode int `json:"deliveryMode"`
16+
CorrelationID string `json:"correlationID"`
17+
ReplyTo string `json:"replyTo"`
18+
Destination ActiveMQDestination `json:"destination"`
19+
Redelivered bool `json:"redelivered"`
20+
Type string `json:"type"`
21+
Expiration int64 `json:"expiration"`
22+
Priority int `json:"priority"`
23+
Data string `json:"data"`
24+
BrokerInTime int64 `json:"brokerInTime"`
25+
BrokerOutTime int64 `json:"brokerOutTime"`
26+
}
27+
28+
type ActiveMQDestination struct {
29+
PhysicalName string `json:"physicalName"`
30+
}

events/activemq_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
package events
3+
4+
import (
5+
"encoding/json"
6+
"testing"
7+
8+
"github.com/aws/aws-lambda-go/events/test"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestActiveMQEventMarshaling(t *testing.T) {
13+
// 1. read JSON from file
14+
inputJson := test.ReadJSONFromFile(t, "./testdata/activemq-event.json")
15+
16+
// 2. de-serialize into Go object
17+
var inputEvent ActiveMQEvent
18+
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
19+
t.Errorf("could not unmarshal event. details: %v", err)
20+
}
21+
22+
// 3. Verify values populated into Go Object, at least one validation per data type
23+
assert.Equal(t, "aws:mq", inputEvent.EventSource)
24+
assert.Equal(t, "arn:aws:mq:us-west-2:533019413397:broker:shask-test:b-0f5b7522-2b41-4f85-a615-735a4e6d96b5", inputEvent.EventSourceARN)
25+
assert.Equal(t, 1, len(inputEvent.Messages))
26+
27+
var message = inputEvent.Messages[0]
28+
assert.Equal(t, "jms/text-message", message.MessageType)
29+
assert.Equal(t, int64(1599863938941), message.Timestamp)
30+
assert.Equal(t, 1, message.DeliveryMode)
31+
assert.Equal(t, "testQueue", message.Destination.PhysicalName)
32+
assert.Equal(t, false, message.Redelivered)
33+
34+
// 4. serialize to JSON
35+
outputJson, err := json.Marshal(inputEvent)
36+
if err != nil {
37+
t.Errorf("could not marshal event. details: %v", err)
38+
}
39+
40+
// 5. check result
41+
assert.JSONEq(t, string(inputJson), string(outputJson))
42+
}
43+
44+
func TestActiveMQMarshalingMalformedJson(t *testing.T) {
45+
test.TestMalformedJson(t, ActiveMQEvent{})
46+
}

events/apigw.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ type APIGatewayRequestIdentity struct {
150150
type APIGatewayWebsocketProxyRequest struct {
151151
Resource string `json:"resource"` // The resource path defined in API Gateway
152152
Path string `json:"path"` // The url path for the caller
153-
HTTPMethod string `json:"httpMethod"`
153+
HTTPMethod string `json:"httpMethod,omitempty"`
154154
Headers map[string]string `json:"headers"`
155155
MultiValueHeaders map[string][]string `json:"multiValueHeaders"`
156156
QueryStringParameters map[string]string `json:"queryStringParameters"`

0 commit comments

Comments
 (0)