|
| 1 | +AWSTemplateFormatVersion: '2010-09-09' |
| 2 | +Transform: AWS::Serverless-2016-10-31 |
| 3 | +Description: Lambda Event Destinations |
| 4 | +Parameters: |
| 5 | + SQSArn: |
| 6 | + Type: String |
| 7 | + Default: my-sqs-arn |
| 8 | + UseExistingQueue: |
| 9 | + Type: String |
| 10 | + AllowedValues: |
| 11 | + - true |
| 12 | + - false |
| 13 | + Default: true |
| 14 | + CreateSNSTopic: |
| 15 | + Type: String |
| 16 | + AllowedValues: |
| 17 | + - true |
| 18 | + - false |
| 19 | + Default: true |
| 20 | +Conditions: |
| 21 | + QueueCreationDisabled: !Equals [!Ref UseExistingQueue, true] |
| 22 | + TopicCreationEnabled: !Equals [!Ref CreateSNSTopic, true] |
| 23 | + |
| 24 | +Resources: |
| 25 | + EventDestinationLambda: |
| 26 | + Type: AWS::Serverless::Function |
| 27 | + Properties: |
| 28 | + EventInvokeConfig: |
| 29 | + MaximumEventAgeInSeconds: 70 |
| 30 | + MaximumRetryAttempts: 1 |
| 31 | + DestinationConfig: |
| 32 | + OnSuccess: |
| 33 | + Type: Lambda |
| 34 | + # If the type is Lambda/EventBridge, Destination property is required. |
| 35 | + Destination: !GetAtt DestinationLambda.Arn |
| 36 | + OnFailure: |
| 37 | + # SQS and SNS will get auto-created if the Destination property is not specified or is AWS::NoValue |
| 38 | + Type: SQS |
| 39 | + CodeUri: ./src/ |
| 40 | + Handler: index.handler |
| 41 | + Runtime: nodejs10.x |
| 42 | + MemorySize: 1024 |
| 43 | + |
| 44 | + EventDestinationSQSSNS: |
| 45 | + Type: AWS::Serverless::Function |
| 46 | + Properties: |
| 47 | + EventInvokeConfig: |
| 48 | + MaximumEventAgeInSeconds: 70 |
| 49 | + MaximumRetryAttempts: 1 |
| 50 | + DestinationConfig: |
| 51 | + OnSuccess: |
| 52 | + Type: SQS |
| 53 | + Destination: !If [QueueCreationDisabled, !Ref SQSArn, !Ref 'AWS::NoValue'] |
| 54 | + OnFailure: |
| 55 | + Type: SNS |
| 56 | + Destination: !If [TopicCreationEnabled, !Ref 'AWS::NoValue', 'SOME-SNS-ARN'] |
| 57 | + CodeUri: ./src/ |
| 58 | + Handler: index.handler |
| 59 | + Runtime: nodejs10.x |
| 60 | + MemorySize: 1024 |
| 61 | + |
| 62 | + DestinationLambda: |
| 63 | + Type: AWS::Serverless::Function |
| 64 | + Properties: |
| 65 | + InlineCode: | |
| 66 | + exports.handler = async (event) => { |
| 67 | + const response = { |
| 68 | + statusCode: 200, |
| 69 | + body: JSON.stringify('Hello from Lambda!'), |
| 70 | + }; |
| 71 | + return response; |
| 72 | + }; |
| 73 | + Handler: index.handler |
| 74 | + Runtime: nodejs10.x |
| 75 | + MemorySize: 1024 |
| 76 | + SNSSubscription: |
| 77 | + Type: AWS::SNS::Subscription |
| 78 | + Condition: TopicCreationEnabled |
| 79 | + Properties: |
| 80 | + |
| 81 | + Protocol: email |
| 82 | + # Refer to the auto-created SNS topic using <function-logical-id>.DestinationTopic |
| 83 | + TopicArn: !Ref EventDestinationSQSSNS.DestinationTopic |
0 commit comments