diff --git a/Gopkg.lock b/Gopkg.lock index 07802c6..5d11958 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,7 +2,7 @@ [[projects]] - digest = "1:6c8d51660e50d38116fe8c29eefc00ce856300329993980f7ce7333a522a6a99" + digest = "1:afb77c095b4e0ba815f114f7e7ef99ffb52a62414a5f86c2ad97371bdcf245de" name = "github.com/aws/aws-lambda-go" packages = [ "events", @@ -11,8 +11,8 @@ "lambdacontext", ] pruneopts = "UT" - revision = "4d30d0ff60440c2d0480a15747c96ee71c3c53d4" - version = "v1.2.0" + revision = "527f5d301d2993af078be6d0b63372786b3fc18f" + version = "v1.8.2" [[projects]] digest = "1:a2c1d0e43bd3baaa071d1b9ed72c27d78169b2b269f71c105ac4ba34b1be4a39" diff --git a/Gopkg.toml b/Gopkg.toml index 76e322f..6c53399 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -27,7 +27,7 @@ [[constraint]] name = "github.com/aws/aws-lambda-go" - version = "1.2.0" + version = "1.8.2" [prune] go-tests = true diff --git a/README.md b/README.md index ac73501..28d14cb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![CircleCI](https://circleci.com/gh/sul-dlss/rialto-derivatives.svg?style=svg)](https://circleci.com/gh/sul-dlss/rialto-derivatives) This project contains Lambda functions that migrate data from Neptune to Solr and Postgres -when an appropriately formatted SNS message is received. In the RIALTO architecture these messages come from https://github.com/sul-dlss/rialto-trigger-rebuild when a full rebuild is needed or from https://github.com/sul-dlss/sparql-loader when a single entity needs to be updated. +when an appropriately formatted SQS message is received. In the RIALTO architecture these messages come from https://github.com/sul-dlss/rialto-trigger-rebuild when a full rebuild is needed or from https://github.com/sul-dlss/sparql-loader when a single entity needs to be updated. ## Running a lambda on localstack @@ -11,7 +11,7 @@ when an appropriately formatted SNS message is received. In the RIALTO architect Start [localstack](https://github.com/localstack/localstack#installing). If you're on a Mac, ensure you are running the docker daemon. ``` -SERVICES=lambda,sns LAMBDA_EXECUTOR=docker localstack start +SERVICES=lambda,sns,sqs LAMBDA_EXECUTOR=docker localstack start ``` ### Blazegraph diff --git a/cmd/postgres/main.go b/cmd/postgres/main.go index 33cee5b..e0f1ce6 100644 --- a/cmd/postgres/main.go +++ b/cmd/postgres/main.go @@ -18,10 +18,10 @@ import ( ) // Handler is the Lambda function handler -func Handler(ctx context.Context, snsEvent events.SNSEvent) { +func Handler(ctx context.Context, sqsEvent events.SQSEvent) { repo := repository.BuildRepository() registry := runtime.NewRegistry(repo, buildDatabase(repo)) - for _, record := range snsEvent.Records { + for _, record := range sqsEvent.Records { msg, err := message.Parse(record) if err != nil { panic(err) diff --git a/cmd/solr/main.go b/cmd/solr/main.go index 3956ec2..e3f3002 100644 --- a/cmd/solr/main.go +++ b/cmd/solr/main.go @@ -15,10 +15,10 @@ import ( ) // Handler is the Lambda function handler -func Handler(ctx context.Context, snsEvent events.SNSEvent) { +func Handler(ctx context.Context, sqsEvent events.SQSEvent) { repo := repository.BuildRepository() registry := runtime.NewRegistry(repo, buildSolrClient(repo)) - for _, record := range snsEvent.Records { + for _, record := range sqsEvent.Records { msg, err := message.Parse(record) if err != nil { panic(err) diff --git a/message/parser.go b/message/parser.go index bd2adcc..27fa020 100644 --- a/message/parser.go +++ b/message/parser.go @@ -6,18 +6,27 @@ import ( "github.com/aws/aws-lambda-go/events" ) -// Message a message (from SNS) that the application understands +// Message a message (from SQS) that the application understands type Message struct { Action string Entities []string Body interface{} } -// Parse transforms a SNSEventRecord into a message -func Parse(record events.SNSEventRecord) (*Message, error) { - data := record.SNS.Message +// SQSBody is the body of an SQS message +type SQSBody struct { + Message string +} + +// Parse transforms an SQSMessage into a message +func Parse(record events.SQSMessage) (*Message, error) { + body := &SQSBody{} + err := json.Unmarshal([]byte(record.Body), body) + if err != nil { + return nil, err + } msg := &Message{} - err := json.Unmarshal([]byte(data), msg) + err = json.Unmarshal([]byte(body.Message), msg) if err != nil { return nil, err } diff --git a/message/parser_test.go b/message/parser_test.go index 0678763..d4c9b29 100644 --- a/message/parser_test.go +++ b/message/parser_test.go @@ -8,11 +8,10 @@ import ( ) func TestParse(t *testing.T) { - evtRecord := events.SNSEventRecord{ - SNS: events.SNSEntity{ - Message: "{\"Action\": \"touch\", \"Entities\":[\"http://example.com/foo1\"] }", - }, + evtRecord := events.SQSMessage{ + Body: "{\"Message\": \"{\\\"Action\\\": \\\"touch\\\", \\\"Entities\\\":[\\\"http://example.com/foo1\\\"] }\"}", } + event, _ := Parse(evtRecord) assert.Equal(t, "touch", event.Action) assert.Equal(t, []string{"http://example.com/foo1"}, event.Entities)