AWSTemplateFormatVersion: 2010-09-09 Transform: AWS::Serverless-2016-10-31 Resources: SchedulingQueue: Type: AWS::SQS::Queue Properties: VisibilityTimeout: 120 SchedulingQueuePolicy: Type: AWS::SQS::QueuePolicy Properties: Queues: - !Ref SchedulingQueue PolicyDocument: Id: AllowIncomingAccess Statement: - Effect: Allow Principal: AWS: - !Ref AWS::AccountId Action: - sqs:ReceiveMessage Resource: - !GetAtt SchedulingQueue.Arn - Effect: Allow Principal: '*' Action: - sqs:SendMessage Resource: - !GetAtt SchedulingQueue.Arn Condition: ArnEquals: aws:SourceArn: !ImportValue 'ClinicDemoProtectionArn' SchedulingLambdaFunction: Type: AWS::Serverless::Function Properties: Runtime: python3.9 Timeout: 60 Handler: index.handler InlineCode: |- import json def handler(event, context): message = json.loads(event['Records'][0]['body']) print("{} received from queue {}".format(message['Message'], event['Records'][0]['eventSourceARN'])) Events: SQS: Type: SQS Properties: Queue: !GetAtt SchedulingQueue.Arn SchedulingSubscription: Type: AWS::SNS::Subscription Properties: TopicArn: !ImportValue 'ClinicDemoProtectionArn' Endpoint: !GetAtt SchedulingQueue.Arn Protocol: sqs