Parameters:
  SNSArn:
    Type: String
    Default: my-sns-arn
Globals:
  Function:
    AutoPublishAlias: live
    EventInvokeConfig:
      MaximumEventAgeInSeconds: 70
      MaximumRetryAttempts: 1
      DestinationConfig:
        OnSuccess:
          Type: Lambda
        OnFailure:
          Type: blah
          Destination: !Ref SNSArn

Resources:
  MyTestFunction:
    Type: AWS::Serverless::Function
    Properties:
      InlineCode: |
        exports.handler = function(event, context, callback) {
            var event_received_at = new Date().toISOString();
            console.log('Event received at: ' + event_received_at);
            console.log('Received event:', JSON.stringify(event, null, 2));

            if (event.Success) {
                console.log("Success");
                context.callbackWaitsForEmptyEventLoop = false;
                callback(null);
            } else {
                console.log("Failure");
                context.callbackWaitsForEmptyEventLoop = false;
                callback(new Error("Failure from event, Success = false, I am failing!"), 'Destination Function Error Thrown');
            }
        };      
      Handler: index.handler
      Runtime: nodejs12.x
      MemorySize: 1024