Skip to content

Commit 02d60a9

Browse files
committed
Merge remote-tracking branch 'upstream/master' into feature/fix-codepipeline-jobs
2 parents 7980b8f + 99b35f2 commit 02d60a9

File tree

103 files changed

+2784
-270
lines changed

Some content is hidden

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

103 files changed

+2784
-270
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: go get build-lambda-zip
2+
on:
3+
push:
4+
branches:
5+
- master
6+
schedule:
7+
- cron: "7 7 * * *"
8+
9+
jobs:
10+
thejob:
11+
runs-on: ${{ matrix.platform }}
12+
name: install build-lambda-zip on ${{ matrix.platform }}
13+
strategy:
14+
matrix:
15+
go-version: [1.12, 1.13]
16+
platform: [ubuntu-latest, macos-latest, windows-latest]
17+
steps:
18+
- name: Setup Go
19+
uses: actions/setup-go@v1
20+
with:
21+
go-version: ${{ matrix.go-version }}
22+
23+
- name: go get
24+
env:
25+
GOPROXY: direct
26+
GO111MODULE: on
27+
run: |
28+
go env
29+
go get -u github.com/aws/aws-lambda-go/cmd/build-lambda-zip@master

.github/workflows/lint.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: tests
2+
on:
3+
push:
4+
pull_request:
5+
6+
jobs:
7+
8+
test:
9+
name: lint
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Set up Go 1.13
13+
uses: actions/setup-go@v1
14+
with:
15+
go-version: 1.13
16+
id: go
17+
18+
- name: Check out code into the Go module directory
19+
uses: actions/checkout@v1
20+
21+
- name: golangci-golint
22+
run: |
23+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.27.0
24+
./bin/golangci-lint run -v ./...
25+

.github/workflows/reviewdog.yml

Lines changed: 17 additions & 0 deletions
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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: tests
2+
on:
3+
push:
4+
pull_request:
5+
6+
jobs:
7+
test:
8+
name: run tests with code coverage
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
go:
13+
- "1.16"
14+
- "1.15"
15+
- "1.14"
16+
- "1.13"
17+
18+
steps:
19+
- name: Set up Go ${{ matrix.go }}
20+
uses: actions/setup-go@v1
21+
with:
22+
go-version: ${{ matrix.go }}
23+
id: go
24+
25+
- name: Check out code into the Go module directory
26+
uses: actions/checkout@v1
27+
28+
- name: go test
29+
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
30+
31+
- name: Upload coverage to Codecov
32+
uses: codecov/codecov-action@v1
33+
if: matrix.go == '1.16'
34+
with:
35+
file: ./coverage.txt

.golangci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
linters:
2+
disable-all: true
3+
enable:
4+
- gofmt
5+
- errcheck
6+
- deadcode
7+
- gosimple
8+
- govet
9+
- ineffassign
10+
- staticcheck
11+
- structcheck
12+
- typecheck
13+
- unused
14+
- varcheck
15+
16+
run:
17+
skip-files:
18+
# These were code-generated, and cannot be changed without breaking RPC compatibility.
19+
- lambda/messages/*.go

.travis.yml

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

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# AWS Lambda for Go
2-
[![GoDoc][1]][2]
3-
[![Build Status][5]][6]
4-
[![GoCard][3]][4]
5-
[![codecov][7]][8]
6-
7-
[1]: https://godoc.org/github.com/aws/aws-lambda-go?status.svg
8-
[2]: https://godoc.org/github.com/aws/aws-lambda-go
9-
[3]: https://goreportcard.com/badge/github.com/aws/aws-lambda-go
10-
[4]: https://goreportcard.com/report/github.com/aws/aws-lambda-go
11-
[5]: https://travis-ci.org/aws/aws-lambda-go.svg?branch=master
12-
[6]: https://travis-ci.org/aws/aws-lambda-go
13-
[7]: https://codecov.io/gh/aws/aws-lambda-go/branch/master/graph/badge.svg
14-
[8]: https://codecov.io/gh/aws/aws-lambda-go
2+
3+
[![tests][1]][2]
4+
[![build-lambda-zip][3]][4]
5+
[![Go Reference][5]][6]
6+
[![GoCard][7]][8]
7+
[![codecov][9]][10]
8+
9+
[1]: https://github.com/aws/aws-lambda-go/workflows/tests/badge.svg
10+
[2]: https://github.com/aws/aws-lambda-go/actions?query=workflow%3Atests
11+
[3]: https://github.com/aws/aws-lambda-go/workflows/go%20get%20build-lambda-zip/badge.svg
12+
[4]: https://github.com/aws/aws-lambda-go/actions?query=workflow%3A%22go+get+build-lambda-zip%22
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
15+
[7]: https://goreportcard.com/badge/github.com/aws/aws-lambda-go
16+
[8]: https://goreportcard.com/report/github.com/aws/aws-lambda-go
17+
[9]: https://codecov.io/gh/aws/aws-lambda-go/branch/master/graph/badge.svg
18+
[10]: https://codecov.io/gh/aws/aws-lambda-go
1519

1620
Libraries, samples, and tools to help Go developers develop AWS Lambda functions.
1721

cfn/wrap.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,25 @@ func lambdaWrapWithClient(lambdaFunction CustomResourceFunction, client httpClie
3434
if funcDidPanic {
3535
r.Status = StatusFailed
3636
r.Reason = "Function panicked, see log stream for details"
37-
r.sendWith(client)
37+
// FIXME: something should be done if an error is returned here
38+
_ = r.sendWith(client)
3839
}
3940
}()
4041

4142
r.PhysicalResourceID, r.Data, err = lambdaFunction(ctx, event)
4243
funcDidPanic = false
4344

44-
if r.PhysicalResourceID == "" {
45-
log.Println("PhysicalResourceID must exist, copying Log Stream name")
46-
r.PhysicalResourceID = lambdacontext.LogStreamName
47-
}
4845
if err != nil {
4946
r.Status = StatusFailed
5047
r.Reason = err.Error()
5148
log.Printf("sending status failed: %s", r.Reason)
5249
} else {
5350
r.Status = StatusSuccess
51+
52+
if r.PhysicalResourceID == "" {
53+
log.Println("PhysicalResourceID must exist on creation, copying Log Stream name")
54+
r.PhysicalResourceID = lambdacontext.LogStreamName
55+
}
5456
}
5557

5658
err = r.sendWith(client)

cfn/wrap_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ func TestCopyLambdaLogStream(t *testing.T) {
4646
return
4747
}
4848

49-
lambdaWrapWithClient(fn, client)(context.TODO(), *testEvent)
49+
_, err := lambdaWrapWithClient(fn, client)(context.TODO(), *testEvent)
50+
assert.NoError(t, err)
5051
lambdacontext.LogStreamName = lgs
5152
}
5253

@@ -72,7 +73,8 @@ func TestPanicSendsFailure(t *testing.T) {
7273
}
7374

7475
assert.Panics(t, func() {
75-
lambdaWrapWithClient(fn, client)(context.TODO(), *testEvent)
76+
_, err := lambdaWrapWithClient(fn, client)(context.TODO(), *testEvent)
77+
assert.NoError(t, err)
7678
})
7779

7880
assert.True(t, didSendStatus, "FAILED should be sent to CloudFormation service")
@@ -99,7 +101,8 @@ func TestDontCopyLogicalResourceId(t *testing.T) {
99101
return
100102
}
101103

102-
lambdaWrapWithClient(fn, client)(context.TODO(), *testEvent)
104+
_, err := lambdaWrapWithClient(fn, client)(context.TODO(), *testEvent)
105+
assert.NoError(t, err)
103106
}
104107

105108
func TestWrappedError(t *testing.T) {
@@ -123,7 +126,8 @@ func TestWrappedError(t *testing.T) {
123126
return
124127
}
125128

126-
lambdaWrapWithClient(fn, client)(context.TODO(), *testEvent)
129+
_, err := lambdaWrapWithClient(fn, client)(context.TODO(), *testEvent)
130+
assert.NoError(t, err)
127131
}
128132

129133
func TestWrappedSendFailure(t *testing.T) {

cmd/build-lambda-zip/main.go

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,48 @@
1+
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved
2+
13
package main
24

35
import (
46
"archive/zip"
57
"errors"
68
"fmt"
79
"io/ioutil"
10+
"log"
811
"os"
912
"path/filepath"
1013

11-
"github.com/urfave/cli"
14+
"github.com/urfave/cli/v2"
1215
)
1316

1417
func main() {
15-
app := cli.NewApp()
16-
app.Name = "build-lambda-zip"
17-
app.Usage = "Put an executable and supplemental files into a zip file that works with AWS Lambda."
18-
app.Flags = []cli.Flag{
19-
&cli.StringFlag{
20-
Name: "output, o",
21-
Value: "",
22-
Usage: "output file path for the zip. Defaults to the first input file name.",
18+
app := &cli.App{
19+
Name: "build-lambda-zip",
20+
Usage: "Put an executable and supplemental files into a zip file that works with AWS Lambda.",
21+
Flags: []cli.Flag{
22+
&cli.StringFlag{
23+
Name: "output",
24+
Aliases: []string{"o"},
25+
Value: "",
26+
Usage: "output file path for the zip. Defaults to the first input file name.",
27+
},
2328
},
24-
}
29+
Action: func(c *cli.Context) error {
30+
if !c.Args().Present() {
31+
return errors.New("no input provided")
32+
}
2533

26-
app.Action = func(c *cli.Context) error {
27-
if !c.Args().Present() {
28-
return errors.New("no input provided")
29-
}
34+
inputExe := c.Args().First()
35+
outputZip := c.String("output")
36+
if outputZip == "" {
37+
outputZip = fmt.Sprintf("%s.zip", filepath.Base(inputExe))
38+
}
3039

31-
inputExe := c.Args().First()
32-
outputZip := c.String("output")
33-
if outputZip == "" {
34-
outputZip = fmt.Sprintf("%s.zip", filepath.Base(inputExe))
35-
}
36-
37-
if err := compressExeAndArgs(outputZip, inputExe, c.Args().Tail()); err != nil {
38-
return fmt.Errorf("failed to compress file: %v", err)
39-
}
40-
return nil
40+
if err := compressExeAndArgs(outputZip, inputExe, c.Args().Tail()); err != nil {
41+
return fmt.Errorf("failed to compress file: %v", err)
42+
}
43+
log.Print("wrote " + outputZip)
44+
return nil
45+
},
4146
}
4247

4348
if err := app.Run(os.Args); err != nil {
@@ -47,6 +52,18 @@ func main() {
4752
}
4853

4954
func writeExe(writer *zip.Writer, pathInZip string, data []byte) error {
55+
if pathInZip != "bootstrap" {
56+
header := &zip.FileHeader{Name: "bootstrap", Method: zip.Deflate}
57+
header.SetMode(0755 | os.ModeSymlink)
58+
link, err := writer.CreateHeader(header)
59+
if err != nil {
60+
return err
61+
}
62+
if _, err := link.Write([]byte(pathInZip)); err != nil {
63+
return err
64+
}
65+
}
66+
5067
exe, err := writer.CreateHeader(&zip.FileHeader{
5168
CreatorVersion: 3 << 8, // indicates Unix
5269
ExternalAttrs: 0777 << 16, // -rwxrwxrwx file permissions

0 commit comments

Comments
 (0)