42
loading...
This website collects cookies to deliver better user experience
node -v
//should output a version
v16.3.1
npm -v
//should output a version
8.1.2
npm install -g serverless
if there is an error about permission, try sudo npm install -g serverless
. serverless -v
//should output like this
Framework Core: 2.69.0
Plugin: 5.5.1
SDK: 4.3.0
Components: 3.18.1
sls -v
//should output the same
Framework Core: 2.69.0
Plugin: 5.5.1
SDK: 4.3.0
Components: 3.18.1
.csv
file as you will not be seeing the aws secret keys anymore. Store it where it is safe and accessible to you..csv
file you just downloaded because you will be copying some of its fields in a bit.serverless config credentials --provider aws --key <key> --secret <secret>
bref/bref
package.composer create-project laravel/laravel serverless-template
cd serverless-template
composer require bref/bref
serverless.yml
on the root directory of your project using this template. serverless.yml
npm install
npm install serverless-prune-plugin
reservedConcurrency
is not like provisionedConcurrency
reservedConcurrency
is the maximum number of concurrency your lambda can scale to. If this has no limit, your lambda concurrency can go as high as 1,000 instances.💸💸provisionedConcurrency
is the minimum number of readily available lambda, or as the word itself, already provisioned. So even though you are not using it, there is already that number of provisioned lambda turned on and running.serverless-prune-plugin
this will automatically just retain the latest code version in S3 bucket..env
file. In a normal server, the cache driver can be installed locally but for a lambda, you will need to outsource that, you can use AWS RDS or AWS Redis / Memcached with a public endpoint or a separate VPC but for this demo, we can put it as an array
.CACHE_DRIVER=array
VIEW_COMPILED_PATH=/tmp/storage/framework/views
SESSION_DRIVER=array
LOG_CHANNEL=stderr
app/Providers/AppServiceProvider.php
we will need to add thispublic function boot()
{
//ensures the directory for compiled views exist
if (! is_dir(config('view.compiled'))) {
mkdir(config('view.compiled'), 0755, true);
}
}
serverless deploy
or sls deploy
This will communicate with AWS to automate stuff on the background. Check the logs if we missed any permissions. This is how it should look like. You should be able to access a URL endpoint and see the default landing page./users/path/to/my/project/serverless-template % sls deploy
Serverless: Running "serverless" installed locally (in service node_modules)
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
........
Serverless: Stack create finished...
Serverless: Ensuring that deployment bucket exists
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service template-serverless-service-sample.zip file to S3 (14.19 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
..........................................
Serverless: Stack update finished...
Service Information
service: template-serverless-service-sample
stage: dev
region: us-east-1
stack: template-serverless-service-sample-dev
resources: 15
api keys:
None
endpoints:
ANY - https://wtv6mun227.execute-api.us-east-1.amazonaws.com/dev
ANY - https://wtv6mun227.execute-api.us-east-1.amazonaws.com/dev/{proxy+}
functions:
web: template-serverless-service-sample-dev-web
artisan: template-serverless-service-sample-dev-artisan
layers:
None
Serverless: Prune: Running post-deployment pruning
Serverless: Prune: Querying for deployed function versions
Serverless: Prune: template-serverless-service-sample-dev-web has 1 additional version published and 0 aliases, 0 versions selected for deletion
Serverless: Prune: template-serverless-service-sample-dev-artisan has 1 additional version published and 0 aliases, 0 versions selected for deletion
Serverless: Prune: Pruning complete.