离线运行无服务器时,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 堆栈,当我手动创建队列时,实现流程也可以工作。
我想这个:
- 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