Skip to content

Commit

Permalink
- Added deployment logic in bootstrap verticle
Browse files Browse the repository at this point in the history
- Ported AWS Lambda functions to Golang
- Added Service Auto Scaling for Fargate
  • Loading branch information
smoell committed May 27, 2018
1 parent c0d8fdc commit f757364
Show file tree
Hide file tree
Showing 27 changed files with 692 additions and 2,460 deletions.
9 changes: 0 additions & 9 deletions services/kinesis-consumer/README.md

This file was deleted.

92 changes: 92 additions & 0 deletions services/kinesis-consumer/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*
*/
package main

import (
"context"
"fmt"
"os"

"github.com/aws-samples/reactive-refarch-cloudformation/services/kinesis-consumer/services/persistence"

model "github.com/aws-samples/reactive-refarch-cloudformation/services/kinesis-consumer/model"
consumer "github.com/aws-samples/reactive-refarch-cloudformation/services/kinesis-consumer/services/consumer"

"github.com/golang/protobuf/proto"

"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
)

var region string
var svc *dynamodb.DynamoDB
var tableName string

func init() {
region = os.Getenv("AWS_REGION")
tableName = os.Getenv("TABLE_NAME")

fmt.Printf("Using region %s\n", region)
fmt.Printf("Using DynamoDB table %s\n", tableName)

// Initialize a session in us-west-2 that the SDK will use to load
// credentials from the shared credentials file ~/.a ws/credentials.
sess, err := session.NewSession(&aws.Config{
Region: aws.String(region)},
)

if err != nil {
fmt.Println("Error creating session:")
fmt.Println(err.Error())
}

// Create DynamoDB client
svc = dynamodb.New(sess)
fmt.Printf("DynamoDB client created")
}

func handler(ctx context.Context, kinesisEvent events.KinesisEvent) error {
for _, record := range kinesisEvent.Records {
kinesisRecord := record.Kinesis
dataBytes := kinesisRecord.Data

msg := &consumer.TrackingEvent{}
if err := proto.Unmarshal(dataBytes, msg); err != nil {
fmt.Println("Got error unmarshalling event:")
fmt.Println(err.Error())
}

event := &model.Message{
UserAgent: msg.UserAgent,
ProgramID: msg.Programid,
Checksum: msg.Checksum,
CustomerID: msg.CustomerId,
CustomerName: msg.CustomerName,
MessageID: msg.MessageId,
ProgramName: msg.ProgramName}

persistence.PersistData(*svc, tableName, *event)
}

return nil
}

func main() {
lambda.Start(handler)
}
30 changes: 30 additions & 0 deletions services/kinesis-consumer/model/structs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*
*/
package model

// Message is an exported type that
// contains all values for a tracking message
type Message struct {
ID string `json:"id"`
UpdatedAt string `json:"updated_at"`
UserAgent string `json:"user_agent"`
ProgramID string `json:"program_id"`
Checksum string `json:"checksum"`
CustomerID int32 `json:"customer_id"`
CustomerName string `json:"customer_name"`
MessageID string `json:"message_id"`
ProgramName string `json:"program_name"`
}
90 changes: 0 additions & 90 deletions services/kinesis-consumer/pom.xml

This file was deleted.

139 changes: 139 additions & 0 deletions services/kinesis-consumer/services/consumer/tracking.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f757364

Please sign in to comment.