A JSII construct lib to build AWS Serverless LAMP with AWS CDK
Project description
Welcome to cdk-serverless-lamp
cdk-serverless-lamp
is a JSII construct library for AWS CDK that allows you to deploy the New Serverless LAMP Stack running PHP Laravel Apps by specifying the local laravel
directory.
By deploying this stack, it creates the following resources for you:
- Amazon API Gateway HTTP API
- AWS Lambda custom runtime with Bref runtime support
- Amazon Aurora for MySQL database cluster with RDS proxy enabled
Usage
Building your serverless Laravel with ServerlessLaravel
construct:
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from cdk_serverless_lamp import ServerlessLaravel
from aws_cdk.core import App, Stack
import path as path
app = App()
stack = Stack(app, "ServerlessLaraval")
# the DatabaseCluster sharing the same vpc with the ServerlessLaravel
db = DatabaseCluster(stack, "DatabaseCluster",
vpc=vpc,
instance_type=InstanceType("t3.small"),
rds_proxy=True
)
# the ServerlessLaravel
ServerlessLaravel(stack, "ServerlessLaravel",
bref_layer_version="arn:aws:lambda:ap-northeast-1:209497400698:layer:php-74-fpm:11",
laravel_path=path.join(__dirname, "../../composer/laravel58-bref"),
vpc=vpc,
database_config={
"writer_endpoint": db.rds_proxy.endpoint
}
)
On deploy complete, the API Gateway URL will be returned in the Output. Click the URL and you will see the Laravel landing page:
Prepare the Laravel and bref
$ git clone https://github.com/pahud/cdk-serverless-lamp.git
$ cd cdk-serverless-lamp
$ mkdir composer && cd composer
# create a laravel project
$ docker run --rm -ti \
--volume $PWD:/app \
composer create-project laravel/laravel laravel58-bref --prefer-dist
# enter this project
$ cd laravel58-bref
# install bref in the vendor
$ docker run --rm -ti \
--volume $PWD:/app \
composer require bref/bref
Configure Laravel with Bref for Lambda
According to the Bref document, we need configure the environment before it can be deployed on Lambda:
edit the .env
file
VIEW_COMPILED_PATH=/tmp/storage/framework/views
# We cannot store sessions to disk: if you don't need sessions (e.g. API) then use `array`
# If you write a website, use `cookie` or store sessions in database.
SESSION_DRIVER=cookie
# Logging to stderr allows the logs to end up in Cloudwatch
LOG_CHANNEL=stderr
edit the app/Providers/AppServiceProvider.php
public function boot()
{
// Make sure the directory for compiled views exist
if (! is_dir(config('view.compiled'))) {
mkdir(config('view.compiled'), 0755, true);
}
}
edit bootstrap/app.php
$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
// add the following statement
// we will configure APP_STORAGE = '/tmp' in Lambda env var
$app->useStoragePath($_ENV['APP_STORAGE'] ?? $app->storagePath());
(credit to @azole)
Amazon RDS Cluster and Proxy
Use DatabaseCluster
construct to create your database clusters.
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
db = DatabaseCluster(stack, "DatabaseCluster",
vpc=vpc,
instance_type=InstanceType("t3.small"),
# enable rds proxy for this cluster
rds_proxy=True,
# one writer and one read replica
instance_capacity=2
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cdk-serverless-lamp-1.3.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ee05457f61aa050d81b09ae09766f4a61c8e5d5dd8023e69445070ae0f6b0e0 |
|
MD5 | 9729d876fbe71e40d7b331312ca7da32 |
|
BLAKE2b-256 | 0a456177ae9fc35260a92bf87925501d25473cdd55e92c604d4548920c9582e1 |
Hashes for cdk_serverless_lamp-1.3.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2c206fd50afa3d05592d658681760a22370ce8888ae585339d13653a2b349a0 |
|
MD5 | 3c6aa43376020c298df36eca12332b08 |
|
BLAKE2b-256 | 4ebccc7dbe2d2ec18c09bee13dc932ff9b0c639cdd5d4ba717b0afdff5800221 |