I am using Bref to run Laravel on AWS Lambda, and here is my serverless.yml configuration:
service: lambdajob
provider:
name: aws
# The AWS region in which to deploy (us-east-1 is the default)
region: us-east-2
# Environment variables
environment:
APP_ENV: ${sls:stage} # Or use ${sls:stage} if you want the environment to match the stage
QUEUE_CONNECTION: sqs
SQS_QUEUE: lambda-jobs-${sls:stage}
SQS_PREFIX: https://sqs.us-east-2.amazonaws.com/xxxxxxxxxxx
CACHE_DRIVER: dynamodb
DYNAMODB_CACHE_TABLE: testtools-staging-cache
LOG_CHANNEL: stderr
TELESCOPE_ENABLED: false
DB_HOST: ${ssm:/${sls:stage}/DB_HOST}
DB_DATABASE: ${ssm:/${sls:stage}/DB_DATABASE}
DB_PASSWORD: ${ssm:/${sls:stage}/DB_PASSWORD}
DB_USERNAME: ${ssm:/${sls:stage}/DB_USERNAME}
AWS_BUCKET: staging
iam:
role: arn:aws:iam::xxxxxxxx:role/lambda-role
package:
exclude:
- .env
- node_modules/**
- public/storage
- resources/js/**
- rr
- docker/**
- storage/logs/**
- storage/app/**
- storage/framework/**
- tests/**
functions:
worker:
handler: BrefLaravelBridgeQueueQueueHandler
timeout: 900
runtime: php-81
events:
- sqs:
arn:
Fn::GetAtt: [ YourQueueName, Arn ]
batchSize: 1
plugins:
# We need to include the Bref plugin
- ./vendor/bref/bref
- serverless-lift
resources:
Resources:
# The queue
YourQueueName:
Type: AWS::SQS::Queue
Properties:
QueueName: lambda-jobs-${sls:stage}
VisibilityTimeout: 900
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:
Fn::GetAtt: [ YourQueueFailedName, Arn ]
# Failed jobs will go into that SQS queue to be stored, until a developer looks at these errors
YourQueueFailedName:
Type: AWS::SQS::Queue
Properties:
QueueName: lambda-jobs-failed-${sls:stage}
MessageRetentionPeriod: 1209600 # maximum retention: 14 days
The configuration works, and the Lambda function executes when a job is triggered. However, I get this error:
Invalid configuration value provided for "token". Expected AwsTokenTokenInterface|AwsCacheInterface|array|bool|callable, but got string
I tried changing the token to AwsTokenToken inside the BrefServiceProvider in fixAwsCredentialsConfig, but then I got this error at /var/task/vendor/aws/aws-sdk-php/src/Signature/SignatureV4.php:328:
taging.ERROR: Object of class AwsTokenToken could not be converted to string {"exception":"[object] (Error(code: 0): Object of class Aws\Token\Token could not be converted to string at /var/task/vendor/aws/aws-sdk-php/src/Signature/SignatureV4.php:328)
Here is the code in BrefServiceProvider:
private function fixAwsCredentialsConfig(): void
{
$accessKeyId = $_SERVER['AWS_ACCESS_KEY_ID'] ?? null;
$sessionToken = $_SERVER['AWS_SESSION_TOKEN'] ?? null;
$sessionToken = new AwsToken($sessionToken); // what I added in BrefServiceProvider
//....
}
Can anyone help me fix this issue?
and these are versions of my packages:
-laravel: 8.83.27
-bref/bref: 2.3.2
-bref/laravel-bridge: 2.4.0