Skip to content

Commit 1f6a299

Browse files
authored
Merge branch 'master' into ci-golint
2 parents bd474e7 + d89e42d commit 1f6a299

File tree

69 files changed

+2580
-152
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2580
-152
lines changed

.travis.yml

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
11
language: go
22

33
go:
4-
- 1.12
5-
- 1.11
6-
- tip
4+
- 1.12.x
5+
- 1.11.x
6+
- tip
7+
8+
env: GO111MODULE=on
79

810
before_install:
9-
- curl -L -s https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 -o $GOPATH/bin/dep
10-
- chmod +x $GOPATH/bin/dep
11+
- go mod download
1112

12-
install:
13-
- dep ensure
13+
install:
1414
- go get golang.org/x/lint/golint
1515
- go get github.com/haya14busa/goverage
1616
- go get github.com/alecthomas/gometalinter
1717

1818
matrix:
19-
include:
20-
- go: 1.12
21-
env: GO111MODULE=on
22-
before_install:
23-
- go mod download
24-
install:
25-
- go get golang.org/x/lint/golint
26-
- go get github.com/haya14busa/goverage
2719
allow_failures:
2820
- go: tip
29-
- go: 1.12
30-
env: GO111MODULE=on
3121
fast_finish: true
3222

3323
notifications:
@@ -37,9 +27,11 @@ before_script:
3727
- PKGS=$(go list ./...)
3828

3929
script:
40-
- diff -u <(echo -n) <(gofmt -d ./) # Fail if a .go file hasn't been formatted with gofmt
41-
- goverage -v -covermode=atomic -coverprofile=coverage.txt $PKGS # Run all tests with coverage
30+
- diff -u <(echo -n) <(gofmt -d ./) # Fail if a .go file hasn't been formatted with gofmt
31+
- goverage -v -race -covermode=atomic -coverprofile=coverage.txt $PKGS # Run all tests with coverage
32+
- go vet -v ./... # static analyisis
33+
- golint $LINT_PKGS # lint - ignore failures for now
4234
- gometalinter --vendor --disable-all --enable=vet --enable=golint ./...
43-
35+
4436
after_success:
45-
- bash <(curl -s https://codecov.io/bash)
37+
- bash <(curl -s https://codecov.io/bash)

Gopkg.lock

Lines changed: 0 additions & 44 deletions
This file was deleted.

Gopkg.toml

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Windows developers may have trouble producing a zip file that marks the binary a
5454

5555
Get the tool
5656
``` shell
57+
set GO111MODULE=on
5758
go.exe get -u github.com/aws/aws-lambda-go/cmd/build-lambda-zip
5859
```
5960

cfn/wrap.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@ package cfn
44

55
import (
66
"context"
7+
"encoding/json"
8+
"errors"
79
"log"
810
"net/http"
911

12+
"github.com/aws/aws-lambda-go/events"
1013
"github.com/aws/aws-lambda-go/lambdacontext"
1114
)
1215

1316
// CustomResourceLambdaFunction is a standard form Lambda for a Custom Resource.
1417
type CustomResourceLambdaFunction func(context.Context, Event) (reason string, err error)
1518

19+
// SNSCustomResourceLambdaFunction is a standard form Lambda for a Custom Resource
20+
// that is triggered via a SNS topic.
21+
type SNSCustomResourceLambdaFunction func(context.Context, events.SNSEvent) (reason string, err error)
22+
1623
// CustomResourceFunction is a representation of the customer's Custom Resource function.
1724
// LambdaWrap will take the returned values and turn them into a response to be sent
1825
// to CloudFormation.
@@ -73,3 +80,24 @@ func lambdaWrapWithClient(lambdaFunction CustomResourceFunction, client httpClie
7380
func LambdaWrap(lambdaFunction CustomResourceFunction) (fn CustomResourceLambdaFunction) {
7481
return lambdaWrapWithClient(lambdaFunction, http.DefaultClient)
7582
}
83+
84+
// LambdaWrapSNS wraps a Lambda handler with support for SNS-based custom
85+
// resources. Usage and purpose otherwise same as LambdaWrap().
86+
func LambdaWrapSNS(lambdaFunction CustomResourceFunction) SNSCustomResourceLambdaFunction {
87+
inner := LambdaWrap(lambdaFunction)
88+
return func(ctx context.Context, event events.SNSEvent) (reason string, err error) {
89+
if len(event.Records) != 1 {
90+
err = errors.New("expected exactly 1 incoming record")
91+
return
92+
}
93+
94+
message := event.Records[0].SNS.Message
95+
96+
var innerEvent Event
97+
if err = json.Unmarshal([]byte(message), &innerEvent); err != nil {
98+
return
99+
}
100+
101+
return inner(ctx, innerEvent)
102+
}
103+
}

cmd/build-lambda-zip/main.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import (
88
"os"
99
"path/filepath"
1010

11-
"gopkg.in/urfave/cli.v1"
11+
"github.com/urfave/cli"
1212
)
1313

1414
func main() {
1515
app := cli.NewApp()
1616
app.Name = "build-lambda-zip"
1717
app.Usage = "Put an executable and supplemental files into a zip file that works with AWS Lambda."
1818
app.Flags = []cli.Flag{
19-
cli.StringFlag{
19+
&cli.StringFlag{
2020
Name: "output, o",
2121
Value: "",
2222
Usage: "output file path for the zip. Defaults to the first input file name.",
@@ -25,7 +25,7 @@ func main() {
2525

2626
app.Action = func(c *cli.Context) error {
2727
if !c.Args().Present() {
28-
return errors.New("No input provided")
28+
return errors.New("no input provided")
2929
}
3030

3131
inputExe := c.Args().First()
@@ -35,7 +35,7 @@ func main() {
3535
}
3636

3737
if err := compressExeAndArgs(outputZip, inputExe, c.Args().Tail()); err != nil {
38-
return fmt.Errorf("Failed to compress file: %v", err)
38+
return fmt.Errorf("failed to compress file: %v", err)
3939
}
4040
return nil
4141
}
@@ -71,7 +71,6 @@ func compressExeAndArgs(outZipPath string, exePath string, args []string) error
7171
if closeErr != nil {
7272
fmt.Fprintf(os.Stderr, "Failed to close zip file: %v\n", closeErr)
7373
}
74-
return
7574
}()
7675

7776
zipWriter := zip.NewWriter(zipFile)

events/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ This package provides input types for Lambda functions that process AWS events.
1414

1515
[CloudFormation Events](../cfn/README.md)
1616

17+
[CloudWatch Events](README_CloudWatch_Events.md)
18+
19+
[CloudWatch Logs](README_CloudWatch_Logs.md)
20+
21+
[Chime Bot Events](README_Chime_Bots.md)
22+
1723
[Code Commit Events](README_CodeCommit.md)
1824

1925
[Cognito Events](README_Cognito.md)
@@ -32,6 +38,8 @@ This package provides input types for Lambda functions that process AWS events.
3238

3339
[Kinesis Firehose Events](README_KinesisFirehose.md)
3440

41+
[Lex Events](README_Lex.md)
42+
3543
[S3 Events](README_S3.md)
3644

3745
[SES Events](README_SES.md)

events/README_ALBTargetGroupEvents.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func handleRequest(ctx context.Context, request events.ALBTargetGroupRequest) (e
2929
fmt.Printf(" %s: %s\n", key, value)
3030
}
3131

32-
return events.ALBTargetGroupResponse{Body: request.Body, StatusCode: 200, StatusDescription: "200 OK", IsBase64Encoded: false}, nil
32+
return events.ALBTargetGroupResponse{Body: request.Body, StatusCode: 200, StatusDescription: "200 OK", IsBase64Encoded: false, Headers: map[string]string{}}}, nil
3333
}
3434

3535
func main() {

events/README_Chime_Bots.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Sample Function
2+
3+
The following is a sample class and Lambda function that receives a Amazon Chime Bot event and handles the various event types accordingly.
4+
5+
```go
6+
7+
package main
8+
9+
import (
10+
"fmt"
11+
"context"
12+
"net/http"
13+
"bytes"
14+
"encoding/json"
15+
"errors"
16+
"strconv"
17+
18+
"github.com/aws/aws-lambda-go/events"
19+
)
20+
21+
func handler(_ context.Context, chimeBotEvent events.ChimeBotEvent) error {
22+
switch chimeBotEvent.EventType {
23+
case "Invite":
24+
if err := message(chimeBotEvent.InboundHTTPSEndpoint.URL, "Thanks for inviting me to this room " + chimeBotEvent.Sender.SenderID); err != nil {
25+
return fmt.Errorf("failed to send webhook message: %v", err)
26+
}
27+
return nil
28+
case "Mention":
29+
if err := message(chimeBotEvent.InboundHTTPSEndpoint.URL, "Thanks for mentioning me " + chimeBotEvent.Sender.SenderID); err != nil {
30+
return fmt.Errorf("failed to send webhook message: %v", err)
31+
}
32+
return nil
33+
case "Remove":
34+
fmt.Printf("I have been removed from %q by %q", chimeBotEvent.Discussion.DiscussionType, chimeBotEvent.Sender.SenderID)
35+
return nil
36+
default:
37+
return fmt.Errorf("event type %q is unsupported", chimeBotEvent.EventType)
38+
}
39+
}
40+
41+
func message(url, content string) (error) {
42+
input := &bytes.Buffer{}
43+
if err := json.NewEncoder(input).Encode(webhookInput{Content:content}); err != nil {
44+
return errors.New("failed to marshal request: " + err.Error())
45+
}
46+
47+
resp, err := http.Post("POST", url, input)
48+
if err != nil {
49+
return errors.New("failed to execute post http request: " + err.Error())
50+
}
51+
52+
if resp != nil && resp.Body != nil {
53+
defer resp.Body.Close()
54+
}
55+
56+
if resp.StatusCode != http.StatusOK {
57+
return errors.New("bad response: status code not is " + strconv.Itoa(http.StatusOK) + " not " + strconv.Itoa(resp.StatusCode))
58+
}
59+
60+
return nil
61+
}
62+
63+
type webhookInput struct {
64+
Content string `json:"Content"`
65+
}
66+
67+
```

events/README_CloudWatch_Events.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
# Sample Function
3+
4+
The following is a Lambda function that receives Amazon CloudWatch event record data as input and writes event detail to Lambda's CloudWatch Logs. Note that by default anything written to Console will be logged as CloudWatch Logs events.
5+
6+
```go
7+
import (
8+
"context"
9+
"fmt"
10+
11+
"github.com/aws/aws-lambda-go/events"
12+
)
13+
14+
func handler(ctx context.Context, event events.CloudWatchEvent) {
15+
fmt.Printf("Detail = %s\n", event.Detail)
16+
}
17+
```

events/README_CloudWatch_Logs.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
# Sample Function
3+
4+
The following is a Lambda function that receives Amazon CloudWatch Logs event record data as input and writes message part to Lambda's CloudWatch Logs. Note that by default anything written to Console will be logged as CloudWatch Logs events.
5+
6+
```go
7+
import (
8+
"context"
9+
"fmt"
10+
11+
"github.com/aws/aws-lambda-go/events"
12+
)
13+
14+
func handler(ctx context.Context, logsEvent events.CloudwatchLogsEvent) {
15+
data, _ := logsEvent.AWSLogs.Parse()
16+
for _, logEvent := range data.LogEvents {
17+
fmt.Printf("Message = %s\n", logEvent.Message)
18+
}
19+
}
20+
```

events/README_CodeBuild.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Sample Function
2+
3+
The following is a sample Lambda function that receives an Amazon CodeBuild event
4+
and writes it to standard output.
5+
6+
```go
7+
import (
8+
"fmt"
9+
"github.com/aws/aws-lambda-go/events"
10+
)
11+
12+
func handleRequest(evt events.CodeBuildEvent) {
13+
fmt.Println(evt)
14+
}
15+
```

events/README_CodeDeploy.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Sample Function
2+
3+
The following is a sample Lambda function that receives an Amazon CodeDeploy event
4+
and writes it to standard output.
5+
6+
```go
7+
import (
8+
"fmt"
9+
"github.com/aws/aws-lambda-go/events"
10+
)
11+
12+
func handleRequest(evt events.CodeDeployEvent) {
13+
fmt.Println(evt)
14+
}
15+
```

0 commit comments

Comments
 (0)