Skip to content

Commit 53e9dad

Browse files
authored
Provide an up-to-date feature-rich example serverless.yml config
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
1 parent c61846e commit 53e9dad

File tree

1 file changed

+102
-38
lines changed

1 file changed

+102
-38
lines changed

stubs/serverless.yml

Lines changed: 102 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,110 @@
1+
# This config skeleton deploys a solid foundation for your Serverless Laravel applications
2+
# - TODO: Ensure you have the serverless-lift plugin installed: serverless plugin install -n serverless-lift
3+
# - TODO: Add your Domain(s) and SSLs within ACM used for Cloudfront - NOTE: THIS **MUST** BE WITHIN THE us-east-1 REGION
4+
15
service: laravel
26

3-
provider:
4-
name: aws
5-
# The AWS region in which to deploy (us-east-1 is the default)
6-
region: us-east-1
7-
# The stage of the application, e.g. dev, production, staging… ('dev' is the default)
8-
stage: dev
9-
runtime: provided.al2
7+
params:
8+
default:
9+
domain: dev.example.com # TODO: Add your staging/dev domain/subdomain here
10+
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
11+
log_retention_days: 5
12+
laravel_env: local
13+
laravel_debug: true
14+
tags: # Tag all of our resources - Useful for cost analysis using
15+
project_name: ${self:service}
16+
stage: ${opt:stage, self:provider.stage}
17+
prod:
18+
domain: prod.example.com # TODO: Add your prod domain here
19+
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
20+
log_retention_days: 30
21+
laravel_env: production
22+
laravel_debug: false
1023

11-
package:
12-
# Directories to exclude from deployment
13-
patterns:
14-
- '!node_modules/**'
15-
- '!public/storage'
16-
- '!resources/assets/**'
17-
- '!storage/**'
18-
- '!tests/**'
24+
provider:
25+
name: aws
26+
region: us-east-1 # The AWS region in which to deploy (us-east-1 is the default)
27+
stage: dev
28+
logRetentionInDays: ${param:log_retention_days}
29+
stackTags: ${param:tags}
30+
tags: ${param:tags}
31+
environment: # Add any environment variables for your Lambda environment here
32+
APP_URL: https://${param:domain}
33+
APP_ENV: ${param:laravel_env}
34+
APP_DEBUG: ${param:laravel_debug}
35+
MAINTENANCE_MODE: ${param:maintenance, null}
36+
QUEUE_CONNECTION: sqs
37+
SQS_QUEUE: ${construct:laravel-default-queue.queueUrl}
1938

2039
functions:
40+
# This function runs the Laravel website/API using PHP-FPM
41+
# If you wish to use Laravel Octane, please comment this function, and replace with the commented one below:
42+
web:
43+
handler: public/index.php
44+
runtime: php-82-fpm
45+
timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
46+
events:
47+
- httpApi: '*'
48+
49+
# This function runs the Laravel website/API using Laravel Octane
50+
# If you wish to use Laravel without Octane, please comment this function, and replace with the one above:
51+
#web:
52+
# handler: Bref\LaravelBridge\Http\OctaneHandler
53+
# environment:
54+
# BREF_LOOP_MAX: 250
55+
# OCTANE_PERSIST_DATABASE_SESSIONS: 1
56+
# runtime: php-82
57+
# timeout: 30 # in seconds
58+
# events:
59+
# - httpApi: '*'
2160

22-
# This function runs the Laravel website/API
23-
web:
24-
handler: public/index.php
25-
timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
26-
layers:
27-
- ${bref:layer.php-81-fpm}
28-
events:
29-
- httpApi: '*'
30-
31-
# This function lets us run artisan commands in Lambda
32-
artisan:
33-
handler: artisan
34-
timeout: 720 # in seconds
35-
layers:
36-
- ${bref:layer.php-80} # PHP
37-
- ${bref:layer.console} # The "console" layer
38-
events:
39-
# We also schedule this function to run the scheduler every minute
40-
- schedule:
41-
rate: rate(1 minute)
42-
input: '"schedule:run"'
61+
# This function lets us run Artisan commands within the Lambda environment
62+
# To use: instead of `php artisan db:seed` you'd run from your local env to seed your Lambda environment:
63+
# serverless bref:cli --args="db:seed"
64+
artisan:
65+
handler: artisan
66+
runtime: php-82-console
67+
timeout: 720 # in seconds
68+
events:
69+
- schedule: # We also schedule this function to run the scheduler every 5 minutes
70+
rate: rate(5 minutes)
71+
input: '"schedule:run"'
72+
73+
constructs:
74+
laravel-default-queue:
75+
type: queue
76+
maxRetries: 1
77+
worker:
78+
handler: Bref\LaravelBridge\Queue\QueueHandler
79+
timeout: 59
80+
runtime: php-82
81+
82+
website:
83+
type: server-side-website
84+
domain: ${param:domain}
85+
certificate: ${param:amazon_ssl_arn}
86+
assets:
87+
'/vendor/*': public/vendor
88+
'/build/assets/*.css': public/build/assets
89+
'/build/assets/*.js': public/build/assets
90+
'/images/*': public/images
91+
'/favicon.ico': public/favicon.ico
92+
'/robots.txt': public/robots.txt
93+
94+
custom:
95+
scriptable:
96+
hooks:
97+
after:deploy:deploy:
98+
- serverless bref:cli --stage=${sls:stage} --args="migrate --force" # Run any new migrations on deployment
4399

44100
plugins:
45-
# We need to include the Bref plugin
46-
- ./vendor/bref/bref
101+
- ./vendor/bref/bref # We need to include the Bref plugin
102+
- serverless-lift
103+
104+
package:
105+
patterns: # Files and directories to exclude from deployment
106+
- '!node_modules/**'
107+
- '!public/storage'
108+
- '!resources/assets/**'
109+
- '!storage/**'
110+
- '!tests/**'

0 commit comments

Comments
 (0)