我有一个连接到AWS Lambda服务的无服务器Laravel api,它尝试按照 Laravel 文档的建议(https://laravel.com/docs/7.x/queues#dispatching-jobs)做一个简单的工作。
我的 ProcessPodcast 作业尝试使用SQS服务,但返回错误。
我有这个错误返回:
Aws\Sqs\Exception\SqsException: Error executing "SendMessage" on "https://sqs.us-east-1.amazonaws.com/your-account-id/$%7Bconstruct:jobs.queueUrl%7D"; AWS HTTP error: Client error: `POST https://sqs.us-east-1.amazonaws.com/your-account-id/$%7Bconstruct:jobs.queueUrl%7D` resulted in a `403 Forbidden` response:
<?xml version="1.0"?><ErrorResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/"><Error><Type>Sender</Type><Code>S (truncated...)
SignatureDoesNotMatch (client): Credential should be scoped to a valid region, not 'us-east-2'. - <?xml version="1.0"?><ErrorResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/"><Error><Type>Sender</Type><Code>SignatureDoesNotMatch</Code><Message>Credential should be scoped to a valid region, not 'us-east-2'. </Message><Detail/></Error><RequestId>548cdabe-0c6a-58a6-971d-80a53eafa104</RequestId></ErrorResponse> in file /var/task/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 195
我的无服务.yml:
service: laravel
provider:
name: aws
# The AWS region in which to deploy (us-east-1 is the default)
region: us-east-2
# The stage of the application, e.g. dev, production, staging… ('dev' is the default)
stage: dev
runtime: provided.al2
lambdaHashingVersion: 20201221
plugins:
- ./vendor/bref/bref
- serverless-lift
package:
exclude:
- node_modules/**
- public/storage
- resources/assets/**
- storage/**
- tests/**
# Directories to exclude from deployment
patterns:
- '!node_modules/**'
- '!public/storage'
- '!resources/assets/**'
- '!storage/**'
- '!tests/**'
functions:
website:
handler: public/index.php
timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
layers:
- ${bref:layer.php-74-fpm}
events:
- http: 'ANY /'
- http: 'ANY /{proxy+}'
- httpApi: '*'
artisan:
handler: artisan
timeout: 120 # in seconds
layers:
- ${bref:layer.php-74} # PHP
- ${bref:layer.console} # The "console" layer
worker:
handler: worker.php
layers:
- ${bref:layer.php-74}
events:
# Declares that our worker is triggered by jobs in SQS
- sqs:
arn: !GetAtt AlertQueue.Arn
# If you create the queue manually, the line above could be:
# arn: 'arn:aws:sqs:us-east-1:1234567890:my_sqs_queue'
# Only 1 item at a time to simplify error handling
batchSize: 1
resources:
Resources:
# The SQS queue
AlertQueue:
Type: AWS::SQS::Queue
Properties:
RedrivePolicy:
maxReceiveCount: 3 # jobs will be retried up to 3 times
# Failed jobs (after the retries) will be moved to the other queue for storage
deadLetterTargetArn: !GetAtt DeadLetterQueue.Arn
# Failed jobs will go into that SQS queue to be stored, until a developer looks at these errors
DeadLetterQueue:
Type: AWS::SQS::Queue
Properties:
MessageRetentionPeriod: 1209600 # maximum retention: 14 days
obs: 我的 serverless 正在运行,没有任何错误,我可以正常访问公共页面...