簡體   English   中英

AWS SQS POST 作業錯誤,無服務器上為 Laravel

[英]Error AWS SQS POST job, with Laravel on serverless

我有一個Laravel api和連接到AWS Lambda服務的無服務器,它試圖按照 Laravel 文檔建議的那樣做一個簡單的工作( https://laravel.com/docs/7.x/queues#dispatching-job )。

我的 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

我的 serveless.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運行正常,沒有報錯,可以正常訪問public頁面...

Laravel 附帶 AWS Lambda 的損壞配置: https://github.com/laravel/laravel/pull/5138#issuecomment-624025825

您需要將token密鑰添加到config/queue.php中的 SQS 配置:

        'sqs' => [
            'driver' => 'sqs',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
+           'token' => env('AWS_SESSION_TOKEN'), // ADD THIS LINE
            'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),

請參閱https://github.com/brefphp/laravel-bridge了解更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM