Skip to content

Commit

Permalink
Provide an up-to-date feature-rich example serverless.yml config
Browse files Browse the repository at this point in the history
Example serverless.yml config for the updated Laravel Bridge for Bref 2.

Default config for Octane support (simply swap the `web` functions over to use)

This uses Lift constructs to:
 - Create a default SQS queue and link to Laravel queues seamlessly
 - Create a Cloudfront website front-end and S3 bucket for serving static assets from within your domain
  • Loading branch information
aran112000 authored Mar 17, 2023
1 parent c61846e commit 53e9dad
Showing 1 changed file with 102 additions and 38 deletions.
140 changes: 102 additions & 38 deletions stubs/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,110 @@
# This config skeleton deploys a solid foundation for your Serverless Laravel applications
# - TODO: Ensure you have the serverless-lift plugin installed: serverless plugin install -n serverless-lift
# - TODO: Add your Domain(s) and SSLs within ACM used for Cloudfront - NOTE: THIS **MUST** BE WITHIN THE us-east-1 REGION

service: laravel

provider:
name: aws
# The AWS region in which to deploy (us-east-1 is the default)
region: us-east-1
# The stage of the application, e.g. dev, production, staging… ('dev' is the default)
stage: dev
runtime: provided.al2
params:
default:
domain: dev.example.com # TODO: Add your staging/dev domain/subdomain here
amazon_ssl_arn: arn:aws:acm:us-east-1:xxxxxxxxx:certificate/xxxx-xxxx-xxxx # TODO: Issue and verify SSL - Must be created within *us-east-1* here: https://us-east-1.console.aws.amazon.com/acm/home?region=us-east-1#/certificates/request/public
log_retention_days: 5
laravel_env: local
laravel_debug: true
tags: # Tag all of our resources - Useful for cost analysis using
project_name: ${self:service}
stage: ${opt:stage, self:provider.stage}
prod:
domain: prod.example.com # TODO: Add your prod domain here
amazon_ssl_arn: arn:aws:acm:us-east-1:xxxxxxxxx:certificate/xxxx-xxxx-xxxx # TODO: Issue and verify SSL - Must be created within *us-east-1* here: https://us-east-1.console.aws.amazon.com/acm/home?region=us-east-1#/certificates/request/public
log_retention_days: 30
laravel_env: production
laravel_debug: false

package:
# Directories to exclude from deployment
patterns:
- '!node_modules/**'
- '!public/storage'
- '!resources/assets/**'
- '!storage/**'
- '!tests/**'
provider:
name: aws
region: us-east-1 # The AWS region in which to deploy (us-east-1 is the default)
stage: dev
logRetentionInDays: ${param:log_retention_days}
stackTags: ${param:tags}
tags: ${param:tags}
environment: # Add any environment variables for your Lambda environment here
APP_URL: https://${param:domain}
APP_ENV: ${param:laravel_env}
APP_DEBUG: ${param:laravel_debug}
MAINTENANCE_MODE: ${param:maintenance, null}
QUEUE_CONNECTION: sqs
SQS_QUEUE: ${construct:laravel-default-queue.queueUrl}

functions:
# This function runs the Laravel website/API using PHP-FPM
# If you wish to use Laravel Octane, please comment this function, and replace with the commented one below:
web:
handler: public/index.php
runtime: php-82-fpm
timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
events:
- httpApi: '*'

# This function runs the Laravel website/API using Laravel Octane
# If you wish to use Laravel without Octane, please comment this function, and replace with the one above:
#web:
# handler: Bref\LaravelBridge\Http\OctaneHandler
# environment:
# BREF_LOOP_MAX: 250
# OCTANE_PERSIST_DATABASE_SESSIONS: 1
# runtime: php-82
# timeout: 30 # in seconds
# events:
# - httpApi: '*'

# This function runs the Laravel website/API
web:
handler: public/index.php
timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
layers:
- ${bref:layer.php-81-fpm}
events:
- httpApi: '*'

# This function lets us run artisan commands in Lambda
artisan:
handler: artisan
timeout: 720 # in seconds
layers:
- ${bref:layer.php-80} # PHP
- ${bref:layer.console} # The "console" layer
events:
# We also schedule this function to run the scheduler every minute
- schedule:
rate: rate(1 minute)
input: '"schedule:run"'
# This function lets us run Artisan commands within the Lambda environment
# To use: instead of `php artisan db:seed` you'd run from your local env to seed your Lambda environment:
# serverless bref:cli --args="db:seed"
artisan:
handler: artisan
runtime: php-82-console
timeout: 720 # in seconds
events:
- schedule: # We also schedule this function to run the scheduler every 5 minutes
rate: rate(5 minutes)
input: '"schedule:run"'

constructs:
laravel-default-queue:
type: queue
maxRetries: 1
worker:
handler: Bref\LaravelBridge\Queue\QueueHandler
timeout: 59
runtime: php-82

website:
type: server-side-website
domain: ${param:domain}
certificate: ${param:amazon_ssl_arn}
assets:
'/vendor/*': public/vendor
'/build/assets/*.css': public/build/assets
'/build/assets/*.js': public/build/assets
'/images/*': public/images
'/favicon.ico': public/favicon.ico
'/robots.txt': public/robots.txt

custom:
scriptable:
hooks:
after:deploy:deploy:
- serverless bref:cli --stage=${sls:stage} --args="migrate --force" # Run any new migrations on deployment

plugins:
# We need to include the Bref plugin
- ./vendor/bref/bref
- ./vendor/bref/bref # We need to include the Bref plugin
- serverless-lift

package:
patterns: # Files and directories to exclude from deployment
- '!node_modules/**'
- '!public/storage'
- '!resources/assets/**'
- '!storage/**'
- '!tests/**'

0 comments on commit 53e9dad

Please sign in to comment.