Skip to content

Commit

Permalink
added support for sqs projects (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
moritzzimmer committed Feb 5, 2020
1 parent 174db78 commit a7b3cdd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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
```

Expand Down
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, 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())
}
2 changes: 1 addition & 1 deletion generate/core/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
}
Expand Down
22 changes: 16 additions & 6 deletions generate/core/templates/main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 -}}
{{end -}}
15 changes: 11 additions & 4 deletions generate/core/templates/terraform/main.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,25 @@ 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"
topic_arn = "arn:aws:sns:eu-west-1:123456789:test-topic"
}
{{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 -}}
}
Expand Down

0 comments on commit a7b3cdd

Please sign in to comment.