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.11.1
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.12.0
Choose a head ref
  • 9 commits
  • 31 files changed
  • 8 contributors

Commits on May 31, 2019

  1. Add Chime Bot event (#201)

    * Add Chime Bot event
    
    * go fmt ./...
    harrisonhjones authored and bmoffatt committed May 31, 2019
    Copy the full SHA
    af0b813 View commit details

Commits on Jul 1, 2019

  1. Minimum working configuration (#207)

    blaines authored and bmoffatt committed Jul 1, 2019
    Copy the full SHA
    5149d77 View commit details

Commits on Jul 2, 2019

  1. Add S3BatchJobEvent (#210)

    * Add S3BatchJobEvent and related structs, tests, test json, and README
    
    * Update README_S3_Batch_Job.md
    
    Arn -> ARN
    
    * Update s3_batch_job.go
    
    S3BucketArn -> S3BucketARN
    jbonzo authored and bmoffatt committed Jul 2, 2019
    Copy the full SHA
    aa4e58e View commit details
  2. Bump testify to 1.3.0 (#204)

    * Bump testify to 1.3.0
    
    * Use latest patch version of Go in CI
    philtay authored and bmoffatt committed Jul 2, 2019
    Copy the full SHA
    c970554 View commit details
  3. Update S3 Event to working Go file (#212)

    * Update S3 Event to working Go file
    
    Example provided does not work without changing the script slightly...
    
    * Update README_S3.md
    
    more tabs
    Aaron Mulgrew authored and bmoffatt committed Jul 2, 2019
    Copy the full SHA
    4b515f5 View commit details

Commits on Jul 5, 2019

  1. Linter pass (#203)

    philtay authored and bmoffatt committed Jul 5, 2019
    Copy the full SHA
    e7b076e View commit details

Commits on Jul 6, 2019

  1. Extend events.SimpleEmailReceiptAction fields (#211)

    * Extend events.SimpleEmailReceiptAction fields
    
    The action object contains different data depending on the type.
    Previously only the fields relevant to the Lambda type were included,
    preventing use of the SimpleEmailReceiptAction for other types.
    
    * Update ses.go
    
    * ReceiptAction FunctionArn -> FunctionARN
    * ReceiptAction json:"smtpReplayCode" -> json:"smtpReplyCode"
    
    * Resolve TestSESEventMarshaling failure
    
    Using omitempty like this will prevent the inclusion of fields with
    empty strings.
    
    There are possibly scenarios where adding omitempty to the existing
    FunctionARN and InvocationType fields would change the behaviour of
    systems that expect the fields to be present and assigned an empty
    string. I've decided that the consistency of the fields when
    Unmarshaling is a bigger priority here though, as the chances of real
    world applications depending on this behaviour seems pretty remote to
    me.
    
    * Extend TestSESEventMarshaling
    
    This test only covered an SES lambda event, and did not cover other
    types of SES events. Adding SES-S3 and SES-SNS events here is improving
    the test coverage.
    
    * Document events.SimpleEmailReceiptAction
    griffithsh authored and bmoffatt committed Jul 6, 2019
    Copy the full SHA
    84efa13 View commit details
  2. Add events for Cognito custom authentication challenge (#168)

    * Add events for Cognito custom authentication challenge
    
    Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
    
    * fix inconsitent whitespace in README
    
    * Fix Cognito challenge answer type
    
    Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
    
    * Merge master and resolve conflicts
    
    Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
    
    * Update cognito.go
    
     ChallengeMetaData -> ChallengeMetadata
    mxpv authored and bmoffatt committed Jul 6, 2019
    Copy the full SHA
    39a255e View commit details

Commits on Jul 23, 2019

  1. cfn: add sns event handler (#208)

    roberth-k authored and bmoffatt committed Jul 23, 2019
    Copy the full SHA
    578ce6d View commit details
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
language: go

go:
- 1.12
- 1.11
- tip
- 1.12.x
- 1.11.x
- tip

env: GO111MODULE=on

before_install:
- go mod download

install:
install:
- go get golang.org/x/lint/golint
- go get github.com/haya14busa/goverage

@@ -28,9 +28,9 @@ before_script:

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

after_success:
- bash <(curl -s https://codecov.io/bash)
28 changes: 28 additions & 0 deletions cfn/wrap.go
Original file line number Diff line number Diff line change
@@ -4,15 +4,22 @@ package cfn

import (
"context"
"encoding/json"
"errors"
"log"
"net/http"

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

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

// SNSCustomResourceLambdaFunction is a standard form Lambda for a Custom Resource
// that is triggered via a SNS topic.
type SNSCustomResourceLambdaFunction func(context.Context, events.SNSEvent) (reason string, err error)

// CustomResourceFunction is a representation of the customer's Custom Resource function.
// LambdaWrap will take the returned values and turn them into a response to be sent
// to CloudFormation.
@@ -73,3 +80,24 @@ func lambdaWrapWithClient(lambdaFunction CustomResourceFunction, client httpClie
func LambdaWrap(lambdaFunction CustomResourceFunction) (fn CustomResourceLambdaFunction) {
return lambdaWrapWithClient(lambdaFunction, http.DefaultClient)
}

// LambdaWrapSNS wraps a Lambda handler with support for SNS-based custom
// resources. Usage and purpose otherwise same as LambdaWrap().
func LambdaWrapSNS(lambdaFunction CustomResourceFunction) SNSCustomResourceLambdaFunction {
inner := LambdaWrap(lambdaFunction)
return func(ctx context.Context, event events.SNSEvent) (reason string, err error) {
if len(event.Records) != 1 {
err = errors.New("expected exactly 1 incoming record")
return
}

message := event.Records[0].SNS.Message

var innerEvent Event
if err = json.Unmarshal([]byte(message), &innerEvent); err != nil {
return
}

return inner(ctx, innerEvent)
}
}
5 changes: 2 additions & 3 deletions cmd/build-lambda-zip/main.go
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ func main() {

app.Action = func(c *cli.Context) error {
if !c.Args().Present() {
return errors.New("No input provided")
return errors.New("no input provided")
}

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

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

zipWriter := zip.NewWriter(zipFile)
2 changes: 2 additions & 0 deletions events/README.md
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@ This package provides input types for Lambda functions that process AWS events.

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

[Chime Bot Events](README_Chime_Bots.md)

[Code Commit Events](README_CodeCommit.md)

[Cognito Events](README_Cognito.md)
2 changes: 1 addition & 1 deletion events/README_ALBTargetGroupEvents.md
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ func handleRequest(ctx context.Context, request events.ALBTargetGroupRequest) (e
fmt.Printf(" %s: %s\n", key, value)
}

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

func main() {
67 changes: 67 additions & 0 deletions events/README_Chime_Bots.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Sample Function

The following is a sample class and Lambda function that receives a Amazon Chime Bot event and handles the various event types accordingly.

```go

package main

import (
"fmt"
"context"
"net/http"
"bytes"
"encoding/json"
"errors"
"strconv"

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

func handler(_ context.Context, chimeBotEvent events.ChimeBotEvent) error {
switch chimeBotEvent.EventType {
case "Invite":
if err := message(chimeBotEvent.InboundHTTPSEndpoint.URL, "Thanks for inviting me to this room " + chimeBotEvent.Sender.SenderID); err != nil {
return fmt.Errorf("failed to send webhook message: %v", err)
}
return nil
case "Mention":
if err := message(chimeBotEvent.InboundHTTPSEndpoint.URL, "Thanks for mentioning me " + chimeBotEvent.Sender.SenderID); err != nil {
return fmt.Errorf("failed to send webhook message: %v", err)
}
return nil
case "Remove":
fmt.Printf("I have been removed from %q by %q", chimeBotEvent.Discussion.DiscussionType, chimeBotEvent.Sender.SenderID)
return nil
default:
return fmt.Errorf("event type %q is unsupported", chimeBotEvent.EventType)
}
}

func message(url, content string) (error) {
input := &bytes.Buffer{}
if err := json.NewEncoder(input).Encode(webhookInput{Content:content}); err != nil {
return errors.New("failed to marshal request: " + err.Error())
}

resp, err := http.Post("POST", url, input)
if err != nil {
return errors.New("failed to execute post http request: " + err.Error())
}

if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}

if resp.StatusCode != http.StatusOK {
return errors.New("bad response: status code not is " + strconv.Itoa(http.StatusOK) + " not " + strconv.Itoa(resp.StatusCode))
}

return nil
}

type webhookInput struct {
Content string `json:"Content"`
}

```
69 changes: 69 additions & 0 deletions events/README_Cognito_UserPools_CustomAuthLambdaTriggers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Sample Function

The following is a sample Lambda functions that are used for custom authentication with Cognito User Pools.
These Lambda triggers issue and verify their own challenges as part of a user pool [custom authentication flow](https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow.html#amazon-cognito-user-pools-custom-authentication-flow).

Please see instructions for setting up the Cognito triggers at https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-challenge.html

Define Auth Challenge Lambda Trigger:
```go
package main

import (
"fmt"

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

func handler(event *events.CognitoEventUserPoolsDefineAuthChallenge) (*events.CognitoEventUserPoolsDefineAuthChallenge, error) {
fmt.Printf("Define Auth Challenge: %+v\n", event)
return event, nil
}

func main() {
lambda.Start(handler)
}
```

Create Auth Challenge Lambda Trigger:
```go
package main

import (
"fmt"

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

func handler(event *events.CognitoEventUserPoolsCreateAuthChallenge) (*events.CognitoEventUserPoolsCreateAuthChallenge, error) {
fmt.Printf("Create Auth Challenge: %+v\n", event)
return event, nil
}

func main() {
lambda.Start(handler)
}
```

Verify Auth Challenge Response Lambda Trigger:
```go
package main

import (
"fmt"

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

func handler(event *events.CognitoEventUserPoolsVerifyAuthChallenge) (*events.CognitoEventUserPoolsVerifyAuthChallenge, error) {
fmt.Printf("Verify Auth Challenge: %+v\n", event)
return event, nil
}

func main() {
lambda.Start(handler)
}
```
24 changes: 17 additions & 7 deletions events/README_S3.md
Original file line number Diff line number Diff line change
@@ -4,17 +4,27 @@ The following is a sample class and Lambda function that receives Amazon S3 even

```go

// main.go
package main

import (
"fmt"
"context"
"github.com/aws/aws-lambda-go/events"
"fmt"
"context"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-lambda-go/events"
)

func handler(ctx context.Context, s3Event events.S3Event) {
for _, record := range s3Event.Records {
s3 := record.S3
fmt.Printf("[%s - %s] Bucket = %s, Key = %s \n", record.EventSource, record.EventTime, s3.Bucket.Name, s3.Object.Key)
}
for _, record := range s3Event.Records {
s3 := record.S3
fmt.Printf("[%s - %s] Bucket = %s, Key = %s \n", record.EventSource, record.EventTime, s3.Bucket.Name, s3.Object.Key)
}
}


func main() {
// Make the handler available for Remote Procedure Call by AWS Lambda
lambda.Start(handler)
}

```
39 changes: 39 additions & 0 deletions events/README_S3_Batch_Job.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Sample Function

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

```go

import (
"fmt"
"context"
"github.com/aws/aws-lambda-go/events"
)

func handler(ctx context.Context, e events.S3BatchJobEvent) (response events.S3BatchJobResponse, err error) {
fmt.Printf("InvocationSchemaVersion: %s\n", e.InvocationSchemaVersion)
fmt.Printf("InvocationID: %s\n", e.InvocationID)
fmt.Printf("Job.ID: %s\n", e.Job.ID)

for _, task := range e.Tasks {
fmt.Printf("TaskID: %s\n", task.TaskID)
fmt.Printf("S3Key: %s\n", task.S3Key)
fmt.Printf("S3VersionID: %s\n", task.S3VersionID)
fmt.Printf("S3BucketARN: %s\n", task.S3BucketARN)

}

fmt.Printf("InvocationSchemaVersion: %s\n", response.InvocationSchemaVersion)
fmt.Printf("TreatMissingKeysAs: %s\n", response.TreatMissingKeysAs)
fmt.Printf("InvocationID: %s\n", response.InvocationID)

for _, result := range response.Results {
fmt.Printf("TaskID: %s\n", result.TaskID)
fmt.Printf("ResultCode: %s\n", result.ResultCode)
fmt.Printf("ResultString: %s\n", result.ResultString)
}

return
}

```
4 changes: 2 additions & 2 deletions events/attributevalue_test.go
Original file line number Diff line number Diff line change
@@ -259,9 +259,9 @@ func Test_DynamoDBAttributeValue_NewAttribute(t *testing.T) {
assert.Equal(t, true, av.Boolean())
}
{
av := NewBinarySetAttribute([][]byte{[]byte{1, 2, 3}})
av := NewBinarySetAttribute([][]byte{{1, 2, 3}})
assert.Equal(t, DataTypeBinarySet, av.DataType())
assert.Equal(t, [][]byte{[]byte{1, 2, 3}}, av.BinarySet())
assert.Equal(t, [][]byte{{1, 2, 3}}, av.BinarySet())
}
{
av := NewListAttribute([]DynamoDBAttributeValue{
31 changes: 31 additions & 0 deletions events/chime_bot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.

package events

import (
"time"
)

type ChimeBotEvent struct {
Sender ChimeBotEventSender `json:"Sender"`
Discussion ChimeBotEventDiscussion `json:"Discussion"`
EventType string `json:"EventType"`
InboundHTTPSEndpoint *ChimeBotEventInboundHTTPSEndpoint `json:"InboundHttpsEndpoint,omitempty"`
EventTimestamp time.Time `json:"EventTimestamp"`
Message string `json:"Message,omitempty"`
}

type ChimeBotEventSender struct {
SenderID string `json:"SenderId"`
SenderIDType string `json:"SenderIdType"`
}

type ChimeBotEventDiscussion struct {
DiscussionID string `json:"DiscussionId"`
DiscussionType string `json:"DiscussionType"`
}

type ChimeBotEventInboundHTTPSEndpoint struct {
EndpointType string `json:"EndpointType"`
URL string `json:"Url"`
}
Loading