0

我正在尝试使用 ElasticMQ 的 Docker 映像和以下 serverless.yml 运行本地设置。但是 serverless-offline-sqs 似乎没有到达 ElasticMQ,因为消息留在队列中并且 Lambda 函数没有触发。

docker run -p 9324:9324 -p 9325:9325 -v $pwd\custom.conf:/opt/elasticmq.conf softwaremill/elasticmq

自定义.conf

include classpath("application.conf")

# What is the outside visible address of this ElasticMQ node
# Used to create the queue URL (may be different from bind address!)
node-address {
  protocol = http
  host = localhost
  port = 9324
  context-path = ""
}

rest-sqs {
  enabled = true
  bind-port = 9324
  bind-hostname = "0.0.0.0"
  # Possible values: relaxed, strict
  sqs-limits = strict
}

rest-stats {
  enabled = true
  bind-port = 9325
  bind-hostname = "0.0.0.0"
}

# Should the node-address be generated from the bind port/hostname
# Set this to true e.g. when assigning port automatically by using port 0.
generate-node-address = false

queues {
  dlq { }
  queue1 { }
  queue2 { }
  queue3 { }
}

queues-storage {
  # See next sections
}

# Region and accountId which will be included in resource ids
aws {
  region = us-west-2
  accountId = 000000000000
}

无服务器.yml

service: lb-dataingestion
configValidationMode: error
frameworkVersion: ">=1.1.0"
useDotenv: true
custom:
  serverless-offline-sqs:
    autoCreate: true   
    apiVersion: '2012-11-05'
    endpoint: http://192.168.0.32:9324
    region: us-west-2
    accessKeyId: x
    secretAccessKey: x
    skipCacheInvalidation: false
  bucket: ${env:BUCKET_NAME}
provider:
  name: aws
  runtime: nodejs12.x
  lambdaHashingVersion: '20201221'
  iam:
    role:
      statements:
      - Effect: Allow
        Action:
          - s3:*
        Resource: "*" 
      - Effect: Allow
        Action:
          - sqs:SendMessage
        Resource:
          Fn::GetAtt:
            - Queue1
            - Arn
  vpc:
    securityGroupIds:
      - ${env:SECURITY_GROUP_ID}
    subnetIds:
      - ${env:SUBNET_ID_AZ_A}
      - ${env:SUBNET_ID_AZ_B}
functions:
  writetosql:
    handler: handler.writetosql
    timeout: 15
    events:
      - sqs:
          arn:
            Fn::GetAtt:
              - Queue1
              - Arn

resources:
  Resources:
    Queue1:
      Type: "AWS::SQS::Queue"
      Properties:
        QueueName: ${env:QUEUE_NAME_QUEUE1}
        RedrivePolicy:
          deadLetterTargetArn:
            "Fn::GetAtt":
              - DLQ
              - Arn
          maxReceiveCount: 1
    Queue2:
      Type: "AWS::SQS::Queue"
      Properties:
        QueueName: ${env:QUEUE_NAME_QUEUE2}   
    Queue3:
      Type: "AWS::SQS::Queue"
      Properties:
        QueueName: ${env:QUEUE_NAME_QUEUE3}   
    DLQ:
      Type: "AWS::SQS::Queue"
      Properties:
        QueueName: ${env:QUEUE_NAME_DLQ}

plugins:
  - serverless-offline
  - serverless-dotenv-plugin
  - serverless-offline-sqs

package:
  patterns:
    - '!artifacts-*/**'
    - '!data-example/**'
    - '!false/**'
    - '!scripts/**'
    - '!.env*'
    - '!serverless.yml.tpl'
    - '!Makefile'
    - '!README.md'
    - '!azure-pipelines.yml'
    - '!.gitignore'

如何使用 Serverless Offline 使其工作?

4

0 回答 0