-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
940 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 post-confirmation 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.CognitoEventUserPoolsPostConfirmation) (events.CognitoEventUserPoolsPostConfirmation, error) { | ||
fmt.Printf("PostConfirmation for user: %s\n", event.UserName) | ||
return event, nil | ||
} | ||
|
||
func main() { | ||
lambda.Start(handler) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Sample Function | ||
|
||
The following is a sample Lambda function that receives Amazon Cognito User Pools pre-signup 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.CognitoEventUserPoolsPreSignup) (events.CognitoEventUserPoolsPreSignup, error) { | ||
fmt.Printf("PreSignup of user: %s\n", event.UserName) | ||
event.Response.AutoConfirmUser = true | ||
return event, nil | ||
} | ||
|
||
func main() { | ||
lambda.Start(handler) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Sample Function | ||
|
||
The following is a sample Lambda function that receives an Amazon Connect 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.) | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/aws/aws-lambda-go/lambda" | ||
) | ||
|
||
func main() { | ||
lambda.Start(handler) | ||
} | ||
|
||
func handler(ctx context.Context, connectEvent events.ConnectEvent) (events.ConnectResponse, error) { | ||
fmt.Printf("Processing Connect event with ContactID %s.\n", connectEvent.Details.ContactData.ContactID) | ||
|
||
fmt.Printf("Invoked with %d parameters\n", len(connectEvent.Details.Parameters)) | ||
for k, v := range connectEvent.Details.Parameters { | ||
fmt.Printf("%s : %s\n", k, v) | ||
} | ||
|
||
resp := events.ConnectResponse{ | ||
"Result": "Success", | ||
"NewAttribute": "NewValue", | ||
} | ||
|
||
return resp, nil | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
# Sample Function | ||
|
||
The following is a sample class and Lambda function that receives Amazon SQS event message data as input, writes some of the message data to CloudWatch Logs, and responds with a 200 status and the same body as the request. (Note that by default anything written to Console will be logged as CloudWatch Logs events.) | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/aws/aws-lambda-go/lambda" | ||
) | ||
|
||
func handler(ctx context.Context, sqsEvent events.SQSEvent) error { | ||
for _, message := range sqsEvent.Records { | ||
fmt.Printf("The message %s for event source %s = %s \n", message.MessageId, message.EventSource, message.Body) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func main() { | ||
lambda.Start(handler) | ||
} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package events | ||
|
||
import "encoding/json" | ||
|
||
// AppSyncResolverTemplate represents the requests from AppSync to Lambda | ||
type AppSyncResolverTemplate struct { | ||
Version string `json:"version"` | ||
Operation AppSyncOperation `json:"operation"` | ||
Payload json.RawMessage `json:"payload"` | ||
} | ||
|
||
// AppSyncOperation specifies the operation type supported by Lambda operations | ||
type AppSyncOperation string | ||
|
||
const ( | ||
// OperationInvoke lets AWS AppSync know to call your Lambda function for every GraphQL field resolver | ||
OperationInvoke AppSyncOperation = "Invoke" | ||
// OperationBatchInvoke instructs AWS AppSync to batch requests for the current GraphQL field | ||
OperationBatchInvoke AppSyncOperation = "BatchInvoke" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package events | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/aws/aws-lambda-go/events/test" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAppSyncResolverTemplate_invoke(t *testing.T) { | ||
inputJSON, err := ioutil.ReadFile("./testdata/appsync-invoke.json") | ||
if err != nil { | ||
t.Errorf("could not open test file. details: %v", err) | ||
} | ||
|
||
var inputEvent AppSyncResolverTemplate | ||
if err = json.Unmarshal(inputJSON, &inputEvent); err != nil { | ||
t.Errorf("could not unmarshal event. details: %v", err) | ||
} | ||
assert.Equal(t, OperationInvoke, inputEvent.Operation) | ||
|
||
outputJSON, err := json.Marshal(inputEvent) | ||
if err != nil { | ||
t.Errorf("could not marshal event. details: %v", err) | ||
} | ||
|
||
test.AssertJsonsEqual(t, inputJSON, outputJSON) | ||
} | ||
|
||
func TestAppSyncResolverTemplate_batchinvoke(t *testing.T) { | ||
inputJSON, err := ioutil.ReadFile("./testdata/appsync-batchinvoke.json") | ||
if err != nil { | ||
t.Errorf("could not open test file. details: %v", err) | ||
} | ||
|
||
var inputEvent AppSyncResolverTemplate | ||
if err = json.Unmarshal(inputJSON, &inputEvent); err != nil { | ||
t.Errorf("could not unmarshal event. details: %v", err) | ||
} | ||
assert.Equal(t, OperationBatchInvoke, inputEvent.Operation) | ||
|
||
outputJSON, err := json.Marshal(inputEvent) | ||
if err != nil { | ||
t.Errorf("could not marshal event. details: %v", err) | ||
} | ||
|
||
test.AssertJsonsEqual(t, inputJSON, outputJSON) | ||
} |
Oops, something went wrong.