Skip to main content

A JSII construct lib to build AWS Serverless LAMP with AWS CDK

Project description

NPM version PyPI version Release

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:

  1. Amazon API Gateway HTTP API
  2. AWS Lambda custom runtime with Bref runtime support
  3. [WIP] Amazon Aurora for MySQL database 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")

ServerlessLaravel(stack, "testing",
    # create a serverless Laraval with custom `brefLayerVersion`
    bref_layer_version="arn:aws:lambda:ap-northeast-1:209497400698:layer:php-74-fpm:11",
    # specify your local laravel path
    laravel_path=path.join(__dirname, "../../composer/laravel58-bref")
)

On deploy complete, the API Gateway URL will be returned in the Output. Click the URL and you will see the Laravel landing page:

laravel-welcome

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)

TODO

  • Add Aurora for MySQL stack
  • Add RDS proxy support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdk-serverless-lamp-1.2.1.tar.gz (25.7 kB view hashes)

Uploaded Source

Built Distribution

cdk_serverless_lamp-1.2.1-py3-none-any.whl (24.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page