Skip to content

Commit

Permalink
added support for new kinesis event (#24)
Browse files Browse the repository at this point in the history
* added support for new kinesis event

we need spring-media/terraform-aws-lambda#49
merged and released as v4.4.0 before

* removed deprecated table name from config map

* added stream name to kinesis blueprint
  • Loading branch information
moritzzimmer committed Feb 3, 2020
1 parent e9f7d28 commit c757f77
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func init() {
rootCmd.AddCommand(newCmd)

newCmd.Flags().BoolP("dry-run", "d", false, "dry run")
newCmd.Flags().StringP("event", "e", "cloudwatch-event", "event type triggering the Lambda function [cloudwatch-event, dynamodb, s3, sns]")
newCmd.Flags().StringP("event", "e", "cloudwatch-event", "event type triggering the Lambda function [cloudwatch-event, dynamodb, kinesis, s3, sns]")
newCmd.Flags().String("ci", "none", "ci provider config file to generate [none, travis]")
viper.BindPFlags(newCmd.Flags())
}
4 changes: 2 additions & 2 deletions generate/core/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func DefaultOpts() *Options {
},
Aws: &Aws{Region: "eu-west-1"},
Terraform: &Terraform{
Version: "0.12.12",
Version: "0.12.20",
Module: &Module{
Source: "spring-media/lambda/aws",
Version: "4.3.0",
Version: "4.4.0",
},
},
}
Expand Down
17 changes: 15 additions & 2 deletions generate/core/templates/main.go.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
{{if or (eq .opts.App.Event "dynamodb") (eq .opts.App.Event "sns") (eq .opts.App.Event "s3") -}}
{{if or (eq .opts.App.Event "dynamodb") (eq .opts.App.Event "kinesis") (eq .opts.App.Event "sns") (eq .opts.App.Event "s3") -}}
"context"
{{end -}}
"fmt"

{{if or (eq .opts.App.Event "dynamodb") (eq .opts.App.Event "sns") (eq .opts.App.Event "s3") -}}
{{if or (eq .opts.App.Event "dynamodb") (eq .opts.App.Event "kinesis") (eq .opts.App.Event "sns") (eq .opts.App.Event "s3") -}}
"github.com/aws/aws-lambda-go/events"
{{end -}}
"github.com/aws/aws-lambda-go/lambda"
Expand Down Expand Up @@ -37,6 +37,19 @@ func handler(ctx context.Context, e events.DynamoDBEvent) {
}
{{end -}}

{{if eq .opts.App.Event "kinesis" -}}
func handler(ctx context.Context, kinesisEvent events.KinesisEvent) error {
for _, record := range kinesisEvent.Records {
kinesisRecord := record.Kinesis
dataBytes := kinesisRecord.Data
dataText := string(dataBytes)

fmt.Printf("%s Data = %s \n", record.EventName, dataText)
}
return nil
}
{{end -}}

{{if eq .opts.App.Event "sns" -}}
func handler(ctx context.Context, snsEvent events.SNSEvent) {
for _, record := range snsEvent.Records {
Expand Down
9 changes: 9 additions & 0 deletions generate/core/templates/terraform/main.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@ module "{{.opts.App.Name}}" {
}
{{end -}}


{{if eq .opts.App.Event "dynamodb" -}}
event = {
type = "dynamodb"
stream_event_source_arn = "arn:aws:dynamodb:eu-west-1:647379381847:table/some-table/stream/some-identifier"
table_name = "some-table"
}
{{end -}}

{{if eq .opts.App.Event "kinesis" -}}
event = {
type = "kinesis"
event_source_arn = "arn:aws:kinesis:eu-central-1:647379381847:stream/some-stream"
stream_name = "some-stream"
}
{{end -}}

{{if eq .opts.App.Event "sns" -}}
event = {
Expand Down

0 comments on commit c757f77

Please sign in to comment.