Skip to content

Instantly share code, notes, and snippets.

@awood45
Last active November 1, 2022 17:57
Show Gist options
  • Save awood45/57f0861adabf735a256b09e58d7c9505 to your computer and use it in GitHub Desktop.
Save awood45/57f0861adabf735a256b09e58d7c9505 to your computer and use it in GitHub Desktop.
Template used for Serverless Office Hours on 2022-11-01 - just bring your own code to process the event!
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
connector-workflow
Sample SAM Template for connector-workflow
Resources:
SourceBucket:
Type: AWS::S3::Bucket
Properties:
NotificationConfiguration:
EventBridgeConfiguration:
EventBridgeEnabled: true
SourceToAggregatorRule:
Type: AWS::Events::Rule
Properties:
State: ENABLED
EventPattern:
source:
- "aws.s3"
detail-type:
- "Object Created"
detail:
bucket:
name:
- !Ref SourceBucket
Targets:
- Arn: !Ref AggregatorTopic
Id: "SnsAggregatorTopic"
# EventBridge to SNS permissions?
EventBridgeToSnsConnector:
Type: AWS::Serverless::Connector
Properties:
Source:
Id: SourceToAggregatorRule
Destination:
Id: AggregatorTopic
Permissions:
- Write
AggregatorTopic:
Type: AWS::SNS::Topic
AggregatorToDeliveryQueueSubscription:
Type: AWS::SNS::Subscription
Properties:
TopicArn: !Ref AggregatorTopic
Endpoint: !GetAtt DeliveryQueue.Arn
Protocol: sqs
# SNS -> SQS permissions?
SnsToSqsConnector:
Type: AWS::Serverless::Connector
Properties:
Source:
Id: AggregatorTopic
Destination:
Id: DeliveryQueue
Permissions:
- Write
DeliveryQueue:
Type: AWS::SQS::Queue
# SQS -> Lambda permissions?
SqsToLambdaConnector:
Type: AWS::Serverless::Connector
Properties:
Source:
Id: DeliveryQueue
Destination:
Id: FinalProcessingFunction
Permissions:
- Read
- Write
QueueToProcessorESM:
Type: AWS::Lambda::EventSourceMapping
DependsOn: SqsToLambdaConnector
Properties:
EventSourceArn: !GetAtt DeliveryQueue.Arn
FunctionName: !Ref FinalProcessingFunction
BatchSize: 10
MaximumBatchingWindowInSeconds: 30
FinalProcessingFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: app/
Handler: app.lambda_handler
Runtime: ruby2.7
Timeout: 5
Tracing: Active
Environment:
Variables:
BUCKET_NAME: !Ref SourceBucket
Architectures:
- x86_64
# Lambda -> S3 permissions?
LambdaReadsS3:
Type: AWS::Serverless::Connector
Properties:
Source:
Id: FinalProcessingFunction
Destination:
Id: SourceBucket
Permissions:
- Read
Outputs:
SourceBucketName:
Value: !Ref SourceBucket
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment