简体   繁体   中英

AWS CloudFormation Template - How to configure Lambda with a SQS queue to pick the item from queue

I am pretty new in AWS CloudFormaton template creation. Could not able to find the way to create a Lambda function which will connect with the SQS queue.

Any example or resource would help me to learn and implement.

You need:

AWS::SQS::Queue
AWS::Lambda::Function
AWS::Lambda::EventSourceMapping

"DequeueInstanceQueue": {
  "Type": "AWS::SQS::Queue",
  "Properties": {
    "VisibilityTimeout": 301
  },
  "DeletionPolicy": "Delete"
},
"DequeueInstanceMapping": {
  "Type": "AWS::Lambda::EventSourceMapping",
  "Properties": {
    "EventSourceArn": {
      "Fn::GetAtt": [
        "DequeueInstanceQueue",
        "Arn"
      ]
    },
    "FunctionName": {
      "Fn::GetAtt": [
        "DequeueInstance",
        "Arn"
      ]
    },
    "BatchSize": "1"
  },
  "DeletionPolicy": "Delete"
},
"DequeueInstance": {
  "Type": "AWS::Lambda::Function",
  "Properties": {
    "Runtime": "dotnetcore2.1",
    "Environment": {
      "Variables": {
        "ServerName": {
          "Fn::ImportValue": {
            "Fn::Sub": "${DatabaseStack}-RdsEndpointAddress"
          }
        },
        "DatabaseUserName": {
          "Fn::ImportValue": {
            "Fn::Sub": "${DatabaseStack}-MasterUsername"
          }
        },
        "Password": {
          "Fn::ImportValue": {
            "Fn::Sub": "${DatabaseStack}-MasterUserPassword"
          }
        },
        "BranchName": {
          "Ref": "DbBranch"
        },
        "DequeueInstanceVehicleQueue": {
          "Ref": "DequeueInstanceVehicleQueue"
        }
      }
    },
    "VpcConfig": {
      "SecurityGroupIds": [
        {
          "Fn::ImportValue": {
            "Fn::Sub": "${DatabaseStack}-DbGroup"
          }
        }
      ],
      "SubnetIds": [
        {
          "Fn::ImportValue": {
            "Fn::Sub": "${NetworkStack}-PrivateSubnet1"
          }
        },
        {
          "Fn::ImportValue": {
            "Fn::Sub": "${NetworkStack}-PrivateSubnet2"
          }
        }
      ]
    },
    "Timeout": 300,
    "Handler": "YadaYada.BubbleBoy.WebApi::YadaYada.BubbleBoy.WebApi.Functions.ProductMaker::DequeueInstance",
    "MemorySize": 3008,
    "Role": {
      "Fn::GetAtt": [
        "DequeueInstanceRole",
        "Arn"
      ]
    },
    "Code": {
      "S3Bucket": {
        "Ref": "YadaYadaBubbleBoyWebApiBucket"
      },
      "S3Key": {
        "Ref": "YadaYadaBubbleBoyWebApiKey"
      }
    }
  },
  "DeletionPolicy": "Delete"
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM