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.12.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.13.0
Choose a head ref
  • 6 commits
  • 21 files changed
  • 6 contributors

Commits on Aug 19, 2019

  1. Copy the full SHA
    19047df View commit details
  2. Add usernameParameter to CognitoEventUserPoolsCustomMessageRequest (#219

    )
    
    The CustomMessage_AdminCreateUser trigger returns a user name and verification code, so the request must include both request.usernameParameter and request.codeParameter. Add the usernameParameter field to the CognitoEventUserPoolsCustomMessageRequest struct to meet this requirement.
    
    https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-custom-message.html
    andrewmostello authored and bmoffatt committed Aug 19, 2019
    Copy the full SHA
    cb30add View commit details

Commits on Aug 20, 2019

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    cb75cfe View commit details
  2. Adds OperationName to API Gateway Proxy Request (#224)

    operationName is included by API Gateway for API's that were imported through OpenAPI spec.
    jmnarloch authored and bmoffatt committed Aug 20, 2019
    Copy the full SHA
    460325b View commit details
  3. events: add codebuild and codedeploy state-change event types (#213)

    * events: add codedeploy event type
    
    * events: add codebuild event type
    
    * events: remove unused CodeBuildStatus
    
    * events: move codebuild time types
    roberth-k authored and bmoffatt committed Aug 20, 2019
    Copy the full SHA
    a5ae086 View commit details
  4. Add event types for Cognito PreAuthentication Lambda trigger (#214)

    * Add Cognito trigger: PreAuthentication
    
    * Add PreAuthentication test event
    markneves authored and bmoffatt committed Aug 20, 2019
    Copy the full SHA
    ec56cb7 View commit details
15 changes: 15 additions & 0 deletions events/README_CodeBuild.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Sample Function

The following is a sample Lambda function that receives an Amazon CodeBuild event
and writes it to standard output.

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

func handleRequest(evt events.CodeBuildEvent) {
fmt.Println(evt)
}
```
15 changes: 15 additions & 0 deletions events/README_CodeDeploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Sample Function

The following is a sample Lambda function that receives an Amazon CodeDeploy event
and writes it to standard output.

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

func handleRequest(evt events.CodeDeployEvent) {
fmt.Println(evt)
}
```
25 changes: 25 additions & 0 deletions events/README_Cognito_UserPools_PreAuthentication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Sample Function

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

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 .

```go
package main

import (
"fmt"

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

func handler(event events.CognitoEventUserPoolsPreAuthentication) (events.CognitoEventUserPoolsPreAuthentication, error) {
fmt.Printf("PreAuthentication of user: %s\n", event.UserName)
return event, nil
}

func main() {
lambda.Start(handler)
}
```
45 changes: 45 additions & 0 deletions events/README_KinesisDataAnalytics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Sample function

The following is an example for an Application Destination Lambda function that receives Amazon Kinesis Data Analytics event records as an input. To send Kinesis Data Analytics output records the Lamdbda function must be compliant with the (required input and return data models)[https://docs.aws.amazon.com/kinesisanalytics/latest/dev/how-it-works-output-lambda.html], so the handler returns a list of delivery statuses for each record.

The following Lambda function receives Amazon Kinesis Data Analytics event record data as an input and writes some of the record data to CloudWatch Logs. For each entry it adds an element to the response slice, marking it delivered. When the logic considers the delivery to be failed the `events.KinesisAnalyticsOutputDeliveryFailed` value should be used for the response `Result` field.


```go
package main

import (
"context"
"encoding/json"
"fmt"
"log"

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

func handler(ctx context.Context, kinesisAnalyticsEvent events.KinesisAnalyticsOutputDeliveryEvent) (events.KinesisAnalyticsOutputDeliveryResponse, error) {
var err error

var responses events.KinesisAnalyticsOutputDeliveryResponse
responses.Records = make([]events.KinesisAnalyticsOutputDeliveryResponseRecord, len(kinesisAnalyticsEvent.Records))

for i, record := range kinesisAnalyticsEvent.Records {
responses.Records[i] = events.KinesisAnalyticsOutputDeliveryResponseRecord{
RecordID: record.RecordID,
Result: events.KinesisAnalyticsOutputDeliveryOK,
}

dataBytes := record.Data
dataText := string(dataBytes)

fmt.Printf("%s Data = %s \n", record.RecordID, dataText)
}
return responses, err
}

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

```
19 changes: 10 additions & 9 deletions events/apigw.go
Original file line number Diff line number Diff line change
@@ -30,15 +30,16 @@ type APIGatewayProxyResponse struct {
// APIGatewayProxyRequestContext contains the information to identify the AWS account and resources invoking the
// Lambda function. It also includes Cognito identity information for the caller.
type APIGatewayProxyRequestContext struct {
AccountID string `json:"accountId"`
ResourceID string `json:"resourceId"`
Stage string `json:"stage"`
RequestID string `json:"requestId"`
Identity APIGatewayRequestIdentity `json:"identity"`
ResourcePath string `json:"resourcePath"`
Authorizer map[string]interface{} `json:"authorizer"`
HTTPMethod string `json:"httpMethod"`
APIID string `json:"apiId"` // The API Gateway rest API Id
AccountID string `json:"accountId"`
ResourceID string `json:"resourceId"`
OperationName string `json:"operationName,omitempty"`
Stage string `json:"stage"`
RequestID string `json:"requestId"`
Identity APIGatewayRequestIdentity `json:"identity"`
ResourcePath string `json:"resourcePath"`
Authorizer map[string]interface{} `json:"authorizer"`
HTTPMethod string `json:"httpMethod"`
APIID string `json:"apiId"` // The API Gateway rest API Id
}

// APIGatewayRequestIdentity contains identity information for the request caller.
29 changes: 29 additions & 0 deletions events/apigw_test.go
Original file line number Diff line number Diff line change
@@ -180,3 +180,32 @@ func TestApiGatewayCustomAuthorizerResponseMarshaling(t *testing.T) {
func TestApiGatewayCustomAuthorizerResponseMalformedJson(t *testing.T) {
test.TestMalformedJson(t, APIGatewayCustomAuthorizerResponse{})
}

func TestApiGatewayRestApiOpenApiRequestMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/apigw-restapi-openapi-request.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}

// de-serialize into Go object
var inputEvent APIGatewayProxyRequest
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}

// validate request context
requestContext := inputEvent.RequestContext
if requestContext.OperationName != "HelloWorld" {
t.Errorf("could not extract operationName from context: %v", requestContext)
}

// serialize to json
outputJSON, err := json.Marshal(inputEvent)
if err != nil {
t.Errorf("could not marshal event. details: %v", err)
}

assert.JSONEq(t, string(inputJSON), string(outputJSON))
}
183 changes: 183 additions & 0 deletions events/codebuild.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package events

import (
"encoding/json"
"time"
)

const (
CodeBuildEventSource = "aws.codebuild"
CodeBuildStateChangeDetailType = "CodeBuild Build State Change"
CodeBuildPhaseChangeDetailType = "CodeBuild Build Phase Change"
)

type CodeBuildPhaseStatus string

const (
CodeBuildPhaseStatusFailed CodeBuildPhaseStatus = "FAILED"
CodeBuildPhaseStatusFault = "FAULT"
CodeBuildPhaseStatusInProgress = "IN_PROGRESS"
CodeBuildPhaseStatusQueued = "QUEUED"
CodeBuildPhaseStatusStopped = "STOPPED"
CodeBuildPhaseStatusSucceeded = "SUCCEEDED"
CodeBuildPhaseStatusTimedOut = "TIMED_OUT"
)

type CodeBuildPhaseType string

const (
CodeBuildPhaseTypeSubmitted CodeBuildPhaseType = "SUBMITTED"
CodeBuildPhaseTypeProvisioning = "PROVISIONING"
CodeBuildPhaseTypeDownloadSource = "DOWNLOAD_SOURCE"
CodeBuildPhaseTypeInstall = "INSTALL"
CodeBuildPhaseTypePreBuild = "PRE_BUILD"
CodeBuildPhaseTypeBuild = "BUILD"
CodeBuildPhaseTypePostBuild = "POST_BUILD"
CodeBuildPhaseTypeUploadArtifacts = "UPLOAD_ARTIFACTS"
CodeBuildPhaseTypeFinalizing = "FINALIZING"
CodeBuildPhaseTypeCompleted = "COMPLETED"
)

// CodeBuildEvent is documented at:
// https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html#sample-build-notifications-ref
type CodeBuildEvent struct {
// AccountID is the id of the AWS account from which the event originated.
AccountID string `json:"account"`

// Region is the AWS region from which the event originated.
Region string `json:"region"`

// DetailType informs the schema of the Detail field. For build state-change
// events, the value will be CodeBuildStateChangeDetailType. For phase-change
// events, it will be CodeBuildPhaseChangeDetailType.
DetailType string `json:"detail-type"`

// Source should be equal to CodeBuildEventSource.
Source string `json:"source"`

// Version is the version of the event's schema.
Version string `json:"version"`

// Time is the event's timestamp.
Time time.Time `json:"time"`

// ID is the GUID of this event.
ID string `json:"id"`

// Resources is a list of ARNs of CodeBuild builds that this event pertains to.
Resources []string `json:"resources"`

// Detail contains information specific to a build state-change or
// build phase-change event.
Detail CodeBuildEventDetail `json:"detail"`
}

type CodeBuildEventDetail struct {
BuildStatus CodeBuildPhaseStatus `json:"build-status"`
ProjectName string `json:"project-name"`
BuildID string `json:"build-id"`
AdditionalInformation CodeBuildEventAdditionalInformation `json:"additional-information"`
CurrentPhase CodeBuildPhaseStatus `json:"current-phase"`
CurrentPhaseContext string `json:"current-phase-context"`
Version string `json:"version"`

CompletedPhaseStatus CodeBuildPhaseStatus `json:"completed-phase-status"`
CompletedPhase CodeBuildPhaseStatus `json:"completed-phase"`
CompletedPhaseContext string `json:"completed-phase-context"`
CompletedPhaseDuration DurationSeconds `json:"completed-phase-duration-seconds"`
CompletedPhaseStart CodeBuildTime `json:"completed-phase-start"`
CompletedPhaseEnd CodeBuildTime `json:"completed-phase-end"`
}

type CodeBuildEventAdditionalInformation struct {
Artifact CodeBuildArtifact `json:"artifact"`

Environment CodeBuildEnvironment `json:"environment"`

Timeout DurationMinutes `json:"timeout-in-minutes"`

BuildComplete bool `json:"build-complete"`

Initiator string `json:"initiator"`

BuildStartTime CodeBuildTime `json:"build-start-time"`

Source CodeBuildSource `json:"source"`

Logs CodeBuildLogs `json:"logs"`

Phases []CodeBuildPhase `json:"phases"`
}

type CodeBuildArtifact struct {
MD5Sum string `json:"md5sum"`
SHA256Sum string `json:"sha256sum"`
Location string `json:"location"`
}

type CodeBuildEnvironment struct {
Image string `json:"image"`
PrivilegedMode bool `json:"privileged-mode"`
ComputeType string `json:"compute-type"`
Type string `json:"type"`
EnvironmentVariables []CodeBuildEnvironmentVariable `json:"environment-variables"`
}

type CodeBuildEnvironmentVariable struct {
// Name is the name of the environment variable.
Name string `json:"name"`

// Type is PLAINTEXT or PARAMETER_STORE.
Type string `json:"type"`

// Value is the value of the environment variable.
Value string `json:"value"`
}

type CodeBuildSource struct {
Location string `json:"location"`
Type string `json:"type"`
}

type CodeBuildLogs struct {
GroupName string `json:"group-name"`
StreamName string `json:"stream-name"`
DeepLink string `json:"deep-link"`
}

type CodeBuildPhase struct {
PhaseContext []interface{} `json:"phase-context"`

StartTime CodeBuildTime `json:"start-time"`

EndTime CodeBuildTime `json:"end-time"`

Duration DurationSeconds `json:"duration-in-seconds"`

PhaseType CodeBuildPhaseType `json:"phase-type"`

PhaseStatus CodeBuildPhaseStatus `json:"phase-status"`
}

type CodeBuildTime time.Time

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

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

func (t *CodeBuildTime) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}

ts, err := time.Parse(codeBuildTimeFormat, s)
if err != nil {
return err
}

*t = CodeBuildTime(ts)
return nil
}
Loading