diff --git a/README.md b/README.md index 4328db9..28c2c09 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ Func is a CLI app to simplify development and deployment of AWS Lambda functions using Go and Terraform. It'll scaffold an optionated project structure generating code for - function code -- build automation using make -- infrastructure and deployment automation using [terraform-aws-lambda](https://github.com/spring-media/terraform-aws-lambda) +- build and deployment automation using make +- IaaS using terraform modules ([terraform-aws-lambda](https://github.com/spring-media/terraform-aws-lambda)) - continuous integration/deployment providers like Travis Func is in an early alpha stage so expect bugs and breaking changes but give it a try! @@ -95,7 +95,7 @@ func new github.com/you/app Flags: --ci string ci provider config file to generate [none, travis] (default "none") -d, --dry-run dry run - -e, --event string event type triggering the Lambda function [cloudwatch-event, dynamodb, s3, sns] (default "cloudwatch-event") + -e, --event string event type triggering the Lambda function [cloudwatch-event, dynamodb, kinesis, s3, sns, sqs] (default "cloudwatch-event") -h, --help help for new ``` diff --git a/cmd/new.go b/cmd/new.go index 8ed11fe..5cf28e9 100644 --- a/cmd/new.go +++ b/cmd/new.go @@ -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, kinesis, s3, sns]") + newCmd.Flags().StringP("event", "e", "cloudwatch-event", "event type triggering the Lambda function [cloudwatch-event, dynamodb, kinesis, s3, sns, sqs]") newCmd.Flags().String("ci", "none", "ci provider config file to generate [none, travis]") viper.BindPFlags(newCmd.Flags()) } diff --git a/generate/core/options.go b/generate/core/options.go index 348ecda..dbec2a6 100644 --- a/generate/core/options.go +++ b/generate/core/options.go @@ -45,7 +45,7 @@ func DefaultOpts() *Options { Version: "0.12.20", Module: &Module{ Source: "spring-media/lambda/aws", - Version: "4.5.0", + Version: "4.6.0", }, }, } diff --git a/generate/core/templates/main.go.tmpl b/generate/core/templates/main.go.tmpl index 3adddc1..ac059e5 100644 --- a/generate/core/templates/main.go.tmpl +++ b/generate/core/templates/main.go.tmpl @@ -50,6 +50,15 @@ func handler(ctx context.Context, kinesisEvent events.KinesisEvent) error { } {{end -}} +{{if eq .opts.App.Event "s3" -}} +func handler(ctx context.Context, s3Event events.S3Event) { + for _, record := range s3Event.Records { + s3 := record.S3 + fmt.Printf("[%s - %s] Bucket = %s, Key = %s \n", record.EventSource, record.EventTime, s3.Bucket.Name, s3.Object.Key) + } +} +{{end -}} + {{if eq .opts.App.Event "sns" -}} func handler(ctx context.Context, snsEvent events.SNSEvent) { for _, record := range snsEvent.Records { @@ -60,11 +69,12 @@ func handler(ctx context.Context, snsEvent events.SNSEvent) { } {{end -}} -{{if eq .opts.App.Event "s3" -}} -func handler(ctx context.Context, s3Event events.S3Event) { - for _, record := range s3Event.Records { - s3 := record.S3 - fmt.Printf("[%s - %s] Bucket = %s, Key = %s \n", record.EventSource, record.EventTime, s3.Bucket.Name, s3.Object.Key) +{{if eq .opts.App.Event "sqs" -}} +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 } -{{end -}} \ No newline at end of file +{{end -}} diff --git a/generate/core/templates/terraform/main.tf.tmpl b/generate/core/templates/terraform/main.tf.tmpl index 4a10772..29c0369 100644 --- a/generate/core/templates/terraform/main.tf.tmpl +++ b/generate/core/templates/terraform/main.tf.tmpl @@ -34,6 +34,14 @@ module "{{.opts.App.Name}}" { } {{end -}} + {{if eq .opts.App.Event "s3" -}} + event = { + type = "s3" + s3_bucket_arn = data.aws_s3_bucket.example.arn + s3_bucket_id = data.aws_s3_bucket.example.id + } + {{end -}} + {{if eq .opts.App.Event "sns" -}} event = { type = "sns" @@ -41,11 +49,10 @@ module "{{.opts.App.Name}}" { } {{end -}} - {{if eq .opts.App.Event "s3" -}} + {{if eq .opts.App.Event "sqs" -}} event = { - type = "s3" - s3_bucket_arn = data.aws_s3_bucket.example.arn - s3_bucket_id = data.aws_s3_bucket.example.id + type = "sqs" + event_source_arn = "arn:aws:sqs:eu-west-1:123456789:test-queue" } {{end -}} }