无服务器离线未创建 Sqs 队列

问题描述 投票:0回答:1

离线运行无服务器时,sqs 队列不会自动创建

    
provider:
  name: aws
  runtime: nodejs20.x
  region: eu-central-1
  environment:
    STAGE: ${sls:stage}
    TEST_QUEUE: ${sls:stage}-${self:service}-TEST_QUEUE

iam:
    role:
      statements:
        - Effect: Allow
          Action:
            - sqs:SendMessage
            - sqs:ReceiveMessage
            - sqs:GetQueueUrl
          Resource:
            - Fn::GetAtt: [ TestQueue, Arn ]
functions:
  testQueue:
    handler: src/functions/test/TestController.handler
    memorySize: 700
    timeout: 900
    reservedConcurrency: 1
    disableLogs: true
    events:
      - sqs:
          batchSize: 10
          arn:
            Fn::GetAtt: [ TestQueue, Arn ]
- Resources:
      TestQueue:
        Type: AWS::SQS::Queue
        Properties:
          QueueName: ${self:provider.environment.TEST_QUEUE}
          VisibilityTimeout: 900
custom:
  serverless-offline-sqs:
    endpoint: http://localhost:9324
    accessKeyId: local
    secretAccessKey: locallocal
    autoCreate: true

在尝试获取 sqs 队列 url 时,它会抛出“指定的队列不存在”。错误

我使用 docker 作为本地 sqs 堆栈,当我手动创建队列时,实现流程也可以工作。

typescript amazon-web-services amazon-sqs serverless serverless-framework
1个回答
0
投票

我想这个:

- Resources:
  TestQueue:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: ${self:provider.environment.TEST_QUEUE}
      VisibilityTimeout: 900

应该是:

 resources:
  Resources:
    TestQueue:
      Type: AWS::SQS::Queue
      Properties:
        QueueName: ${self:provider.environment.TEST_QUEUE}
        VisibilityTimeout: 900
© www.soinside.com 2019 - 2024. All rights reserved.