Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: aws/aws-lambda-go
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.13.2
Choose a base ref
...
head repository: aws/aws-lambda-go
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.13.3
Choose a head ref
  • 8 commits
  • 29 files changed
  • 7 contributors

Commits on Sep 12, 2019

  1. Update README_Cognito_UserPools_PreTokenGen.md (#230)

    Fix typos
    csakshaug authored and bmoffatt committed Sep 12, 2019
    Copy the full SHA
    02a2e04 View commit details

Commits on Sep 18, 2019

  1. Add missing 'apiKeyId' to APIGatewayRequestIdentity (#235)

    * Add missing 'apiKeyId' to APIGatewayRequestIdentity
    
    * Update apigw tests with 'apiKeyId'
    nhibberd authored and bmoffatt committed Sep 18, 2019
    Copy the full SHA
    1a58586 View commit details

Commits on Oct 9, 2019

  1. Copy the full SHA
    319e4b3 View commit details

Commits on Oct 10, 2019

  1. Fix the use of a variable on range scope (#238)

    As is, the code isn't wrong, but if concurrency is introduced in the
    tests, this gonna be a problem.
    diegobernardes authored and bmoffatt committed Oct 10, 2019
    Copy the full SHA
    81cc163 View commit details

Commits on Oct 11, 2019

  1. Add phase-type of QUEUED as constant (#234)

    * Add phase-type of QUEUED as constant
    
    * Add to the test data also
    
    * fix assertions
    whithajess authored and bmoffatt committed Oct 11, 2019
    Copy the full SHA
    62a881e View commit details

Commits on Oct 14, 2019

  1. fixed loses precision for large values (#227)

    * fixed loses precision for large values #186
    
    * update
    joeke80215 authored and bmoffatt committed Oct 14, 2019
    Copy the full SHA
    e8b9e00 View commit details

Commits on Oct 23, 2019

  1. Improvements to golint (#243)

    * First improvements to golint
    
    * Add comment to methods and structs as suggested by golint
    
    * Improvements to lint
    
    * Improve more some golint
    
    * Fix typo regarding IAMPolicyStatement
    robertoduessmann authored and bmoffatt committed Oct 23, 2019
    Copy the full SHA
    476be7d View commit details
  2. Add CloudWatch README (#242)

    * Add CloudWatch README
    
    * Update README_CloudWatch_Events.md
    
    * Update README_CloudWatch_Logs.md
    Tensho authored and bmoffatt committed Oct 23, 2019
    Copy the full SHA
    b5b7267 View commit details
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -27,10 +27,10 @@ before_script:
- LINT_PKGS=$(go list ./... | grep -Ev 'aws-lambda-go/lambda')

script:
- diff -u <(echo -n) <(gofmt -d ./) # Fail if a .go file hasn't been formatted with gofmt
- goverage -v -covermode=atomic -coverprofile=coverage.txt $PKGS # Run all tests with coverage
- go vet -v ./... # static analyisis
- golint $LINT_PKGS # lint - ignore failures for now
- diff -u <(echo -n) <(gofmt -d ./) # Fail if a .go file hasn't been formatted with gofmt
- goverage -v -race -covermode=atomic -coverprofile=coverage.txt $PKGS # Run all tests with coverage
- go vet -v ./... # static analyisis
- golint $LINT_PKGS # lint - ignore failures for now

after_success:
- bash <(curl -s https://codecov.io/bash)
4 changes: 4 additions & 0 deletions events/README.md
Original file line number Diff line number Diff line change
@@ -14,6 +14,10 @@ This package provides input types for Lambda functions that process AWS events.

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

[CloudWatch Events](README_CloudWatch_Events.md)

[CloudWatch Logs](README_CloudWatch_Logs.md)

[Chime Bot Events](README_Chime_Bots.md)

[Code Commit Events](README_CodeCommit.md)
17 changes: 17 additions & 0 deletions events/README_CloudWatch_Events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# Sample Function

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.

```go
import (
"context"
"fmt"

"github.com/aws/aws-lambda-go/events"
)

func handler(ctx context.Context, event events.CloudWatchEvent) {
fmt.Printf("Detail = %s\n", event.Detail)
}
```
20 changes: 20 additions & 0 deletions events/README_CloudWatch_Logs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

# Sample Function

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.

```go
import (
"context"
"fmt"

"github.com/aws/aws-lambda-go/events"
)

func handler(ctx context.Context, logsEvent events.CloudwatchLogsEvent) {
data, _ := logsEvent.AWSLogs.Parse()
for _, logEvent := range data.LogEvents {
fmt.Printf("Message = %s\n", logEvent.Message)
}
}
```
2 changes: 1 addition & 1 deletion events/README_Cognito_UserPools_PreTokenGen.md
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ import (

func handler(event events.CognitoEventUserPoolsPreTokenGen) (events.CognitoEventUserPoolsPreTokenGen, error) {
fmt.Printf("PreTokenGen of user: %s\n", event.UserName)
event.Response.ClaimOverrideDetails.ClaimsToSupress = []string{"family_name"}
event.Response.ClaimsOverrideDetails.ClaimsToSuppress = []string{"family_name"}
return event, nil
}

2 changes: 2 additions & 0 deletions events/apigw.go
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ type APIGatewayRequestIdentity struct {
CognitoIdentityID string `json:"cognitoIdentityId"`
Caller string `json:"caller"`
APIKey string `json:"apiKey"`
APIKeyID string `json:"apiKeyId"`
AccessKey string `json:"accessKey"`
SourceIP string `json:"sourceIp"`
CognitoAuthenticationType string `json:"cognitoAuthenticationType"`
@@ -167,6 +168,7 @@ type APIGatewayCustomAuthorizerPolicy struct {
Statement []IAMPolicyStatement
}

// IAMPolicyStatement represents one statement from IAM policy with action, effect and resource
type IAMPolicyStatement struct {
Action []string
Effect string
7 changes: 6 additions & 1 deletion events/attributevalue.go
Original file line number Diff line number Diff line change
@@ -75,7 +75,12 @@ func (av DynamoDBAttributeValue) Number() string {
// of an int64 of the appropriate sign.
// Method panics if the attribute is not of type Number.
func (av DynamoDBAttributeValue) Integer() (int64, error) {
s, err := strconv.ParseFloat(av.Number(), 64)
number := av.Number()
value, err := strconv.ParseInt(number, 10, 64)
if err == nil {
return value, nil
}
s, err := strconv.ParseFloat(number, 64)
return int64(s), err
}

1 change: 1 addition & 0 deletions events/attributevalue_test.go
Original file line number Diff line number Diff line change
@@ -211,6 +211,7 @@ func TestAccessWithWrongTypePanics(t *testing.T) {
}

for _, testCase := range testCases {
testCase := testCase
var av DynamoDBAttributeValue
err := json.Unmarshal([]byte(testCase.input), &av)
assert.Nil(t, err)
3 changes: 2 additions & 1 deletion events/chime_bot_test.go
Original file line number Diff line number Diff line change
@@ -4,10 +4,10 @@ package events
import (
"encoding/json"
"testing"
"time"

"github.com/aws/aws-lambda-go/events/test"
"github.com/stretchr/testify/assert"
"time"
)

func TestChimeBotEventMarshaling(t *testing.T) {
@@ -116,6 +116,7 @@ func TestChimeBotEventMarshaling(t *testing.T) {
}

for name, test := range tests {
test := test
t.Run(name, func(t *testing.T) {
var testEvent ChimeBotEvent
if err := json.Unmarshal([]byte(test.inputJSON), &testEvent); err != nil {
2 changes: 1 addition & 1 deletion events/cloudwatch_logs.go
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ type CloudwatchLogsData struct {
LogEvents []CloudwatchLogsLogEvent `json:"logEvents"`
}

// LogEvent represents a log entry from cloudwatch logs
// CloudwatchLogsLogEvent represents a log entry from cloudwatch logs
type CloudwatchLogsLogEvent struct {
ID string `json:"id"`
Timestamp int64 `json:"timestamp"`
2 changes: 2 additions & 0 deletions events/cloudwatch_logs_test.go
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ func TestCloudwatchLogs(t *testing.T) {
},
},
} {
test := test
t.Run(test.name, func(t *testing.T) {
inputJson := tst.ReadJSONFromFile(t, test.eventJson)

@@ -71,6 +72,7 @@ func TestCloudwatchLogsParse(t *testing.T) {
},
},
} {
test := test
t.Run(test.name, func(t *testing.T) {
inputJson := tst.ReadJSONFromFile(t, test.eventJson)

2 changes: 1 addition & 1 deletion events/code_commit.go
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ func (t *CodeCommitEventTime) UnmarshalJSON(data []byte) error {
return err
}

// represents a CodeCommit record
// CodeCommitRecord represents a CodeCommit record
type CodeCommitRecord struct {
EventID string `json:"eventId"`
EventVersion string `json:"eventVersion"`
4 changes: 4 additions & 0 deletions events/code_commit_test.go
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ func TestCodeCommitReference(t *testing.T) {
}

for _, c := range cases {
c := c
t.Run(c.Name, func(t *testing.T) {
test.AssertJsonBytes(t, c.Input, &CodeCommitReference{})
})
@@ -69,6 +70,7 @@ func TestCodeCommitCodeCommit(t *testing.T) {
}

for _, c := range cases {
c := c
t.Run(c.Name, func(t *testing.T) {
test.AssertJsonBytes(t, c.Input, &CodeCommitCodeCommit{})
})
@@ -128,6 +130,7 @@ func TestCodeCommitRecord(t *testing.T) {
}

for _, c := range cases {
c := c
t.Run(c.Name, func(t *testing.T) {
test.AssertJsonBytes(t, c.Input, &CodeCommitRecord{})
})
@@ -150,6 +153,7 @@ func TestCodeCommitEvent(t *testing.T) {
}

for _, c := range cases {
c := c
t.Run(c.Name, func(t *testing.T) {
test.AssertJsonBytes(t, c.Input, &CodeCommitEvent{})
})
14 changes: 14 additions & 0 deletions events/codebuild.go
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ const (
CodeBuildPhaseChangeDetailType = "CodeBuild Build Phase Change"
)

// CodeBuildPhaseStatus represents the status of code build phase (i.e. failed, in progress)
type CodeBuildPhaseStatus string

const (
@@ -23,10 +24,12 @@ const (
CodeBuildPhaseStatusTimedOut = "TIMED_OUT"
)

// CodeBuildPhaseType represents the type of the code build phase (i.e. submitted, install)
type CodeBuildPhaseType string

const (
CodeBuildPhaseTypeSubmitted CodeBuildPhaseType = "SUBMITTED"
CodeBuildPhaseTypeQueued = "QUEUED"
CodeBuildPhaseTypeProvisioning = "PROVISIONING"
CodeBuildPhaseTypeDownloadSource = "DOWNLOAD_SOURCE"
CodeBuildPhaseTypeInstall = "INSTALL"
@@ -72,6 +75,7 @@ type CodeBuildEvent struct {
Detail CodeBuildEventDetail `json:"detail"`
}

// CodeBuildEventDetail represents the all details related to the code build event
type CodeBuildEventDetail struct {
BuildStatus CodeBuildPhaseStatus `json:"build-status"`
ProjectName string `json:"project-name"`
@@ -89,6 +93,7 @@ type CodeBuildEventDetail struct {
CompletedPhaseEnd CodeBuildTime `json:"completed-phase-end"`
}

//CodeBuildEventAdditionalInformation represents additional informations to the code build event
type CodeBuildEventAdditionalInformation struct {
Artifact CodeBuildArtifact `json:"artifact"`

@@ -109,12 +114,14 @@ type CodeBuildEventAdditionalInformation struct {
Phases []CodeBuildPhase `json:"phases"`
}

// CodeBuildArtifact represents the artifact provided to build
type CodeBuildArtifact struct {
MD5Sum string `json:"md5sum"`
SHA256Sum string `json:"sha256sum"`
Location string `json:"location"`
}

// CodeBuildEnvironment represents the environment for a build
type CodeBuildEnvironment struct {
Image string `json:"image"`
PrivilegedMode bool `json:"privileged-mode"`
@@ -123,6 +130,7 @@ type CodeBuildEnvironment struct {
EnvironmentVariables []CodeBuildEnvironmentVariable `json:"environment-variables"`
}

// CodeBuildEnvironmentVariable encapsulate environment variables for the code build
type CodeBuildEnvironmentVariable struct {
// Name is the name of the environment variable.
Name string `json:"name"`
@@ -134,17 +142,20 @@ type CodeBuildEnvironmentVariable struct {
Value string `json:"value"`
}

// CodeBuildSource represent the code source will be build
type CodeBuildSource struct {
Location string `json:"location"`
Type string `json:"type"`
}

// CodeBuildLogs gives the log details of a code build
type CodeBuildLogs struct {
GroupName string `json:"group-name"`
StreamName string `json:"stream-name"`
DeepLink string `json:"deep-link"`
}

// CodeBuildPhase represents the phase of a build and its details
type CodeBuildPhase struct {
PhaseContext []interface{} `json:"phase-context"`

@@ -159,14 +170,17 @@ type CodeBuildPhase struct {
PhaseStatus CodeBuildPhaseStatus `json:"phase-status"`
}

// CodeBuildTime represents the time of the build
type CodeBuildTime time.Time

const codeBuildTimeFormat = "Jan 2, 2006 3:04:05 PM"

// MarshalJSON converts a given CodeBuildTime to json
func (t CodeBuildTime) MarshalJSON() ([]byte, error) {
return json.Marshal(time.Time(t).Format(codeBuildTimeFormat))
}

// UnmarshalJSON converts a given json to a CodeBuildTime
func (t *CodeBuildTime) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
19 changes: 18 additions & 1 deletion events/codebuild_test.go
Original file line number Diff line number Diff line change
@@ -2,10 +2,11 @@ package events

import (
"encoding/json"
"github.com/stretchr/testify/require"
"io/ioutil"
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestUnmarshalCodeBuildEvent(t *testing.T) {
@@ -71,6 +72,14 @@ func TestUnmarshalCodeBuildEvent(t *testing.T) {
PhaseType: CodeBuildPhaseTypeSubmitted,
PhaseStatus: CodeBuildPhaseStatusSucceeded,
},
{
PhaseContext: []interface{}{},
StartTime: CodeBuildTime(time.Date(2017, 9, 1, 16, 12, 29, 0, time.UTC)),
EndTime: CodeBuildTime(time.Date(2019, 9, 13, 4, 12, 29, 0, time.UTC)),
Duration: DurationSeconds(0),
PhaseType: CodeBuildPhaseTypeQueued,
PhaseStatus: CodeBuildPhaseStatusSucceeded,
},
{
PhaseContext: []interface{}{},
StartTime: CodeBuildTime(time.Date(2017, 9, 1, 16, 12, 29, 0, time.UTC)),
@@ -200,6 +209,14 @@ func TestUnmarshalCodeBuildEvent(t *testing.T) {
PhaseType: CodeBuildPhaseTypeSubmitted,
PhaseStatus: CodeBuildPhaseStatusSucceeded,
},
{
PhaseContext: []interface{}{},
StartTime: CodeBuildTime(time.Date(2017, 9, 1, 16, 12, 29, 0, time.UTC)),
EndTime: CodeBuildTime(time.Date(2019, 9, 13, 4, 12, 29, 0, time.UTC)),
Duration: DurationSeconds(0),
PhaseType: CodeBuildPhaseTypeQueued,
PhaseStatus: CodeBuildPhaseStatusSucceeded,
},
{
PhaseContext: []interface{}{},
StartTime: CodeBuildTime(time.Date(2017, 9, 1, 16, 12, 29, 0, time.UTC)),
4 changes: 4 additions & 0 deletions events/duration.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import (

type DurationSeconds time.Duration

// UnmarshalJSON converts a given json to a DurationSeconds
func (duration *DurationSeconds) UnmarshalJSON(data []byte) error {
var seconds float64
if err := json.Unmarshal(data, &seconds); err != nil {
@@ -18,13 +19,15 @@ func (duration *DurationSeconds) UnmarshalJSON(data []byte) error {
return nil
}

// MarshalJSON converts a given DurationSeconds to json
func (duration DurationSeconds) MarshalJSON() ([]byte, error) {
seconds := time.Duration(duration).Seconds()
return json.Marshal(int64(math.Ceil(seconds)))
}

type DurationMinutes time.Duration

// UnmarshalJSON converts a given json to a DurationMinutes
func (duration *DurationMinutes) UnmarshalJSON(data []byte) error {
var minutes float64
if err := json.Unmarshal(data, &minutes); err != nil {
@@ -35,6 +38,7 @@ func (duration *DurationMinutes) UnmarshalJSON(data []byte) error {
return nil
}

// MarshalJSON converts a given DurationMinutes to json
func (duration DurationMinutes) MarshalJSON() ([]byte, error) {
minutes := time.Duration(duration).Minutes()
return json.Marshal(int64(math.Ceil(minutes)))
2 changes: 1 addition & 1 deletion events/dynamodb.go
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ type DynamoDBUserIdentity struct {
PrincipalID string `json:"principalId"`
}

// A description of a single data modification that was performed on an item
// DynamoDBStreamRecord represents a description of a single data modification that was performed on an item
// in a DynamoDB table.
type DynamoDBStreamRecord struct {

2 changes: 2 additions & 0 deletions events/s3.go
Original file line number Diff line number Diff line change
@@ -6,10 +6,12 @@ import (
"time"
)

// S3Event which wrap an array of S3EventRecord
type S3Event struct {
Records []S3EventRecord `json:"Records"`
}

// S3EventRecord which wrap record data
type S3EventRecord struct {
EventVersion string `json:"eventVersion"`
EventSource string `json:"eventSource"`
Loading