Skip to content

Instantly share code, notes, and snippets.

@tapasdatta
Created August 21, 2021 09:54
Show Gist options
  • Select an option

  • Save tapasdatta/fd8eddf7e06187a46925d49473c332c9 to your computer and use it in GitHub Desktop.

Select an option

Save tapasdatta/fd8eddf7e06187a46925d49473c332c9 to your computer and use it in GitHub Desktop.
serverless configuration with laravel bref + dynamodb cache
service: test-func
useDotenv: true
provider:
name: aws
region: us-east-1
runtime: provided.al2
stage: ${opt:stage, 'dev'}
environment:
APP_ENV: production
APP_DEBUG: false # set to false when moving to production
APP_KEY: 'base64:/EStlF5sExBpWdQ3eB/h+F2zzKGDc5bvDzwe0KD8ZPg='
# Store cache in a DynamoDB table
CACHE_PREFIX: test_cace
CACHE_DRIVER: dynamodb
DYNAMODB_CACHE_TABLE: !Ref Cache
# Enable new serverless.yml features to avoid deprecation warnings
apiGateway:
shouldStartNameWithService: true
lambdaHashingVersion: 20201221
iamRoleStatements:
- Effect: 'Allow'
Action:
- 'dynamodb:GetItem'
- 'dynamodb:PutItem'
Resource: "*"
#Enabled CORS
httpApi:
cors: true
package:
patterns:
- '!node_modules/**'
- '!public/storage'
- '!resources/assets/**'
- '!storage/**'
- '!tests/**'
- '!.env'
functions:
# This function runs the Laravel website/API
api:
handler: public/index.php
timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
layers:
- ${bref:layer.php-74-fpm}
events:
- httpApi: '*'
# This function lets us run artisan commands in Lambda
artisan:
handler: artisan
timeout: 120 # in seconds
layers:
- ${bref:layer.php-74} # PHP
- ${bref:layer.console} # The "console" layer
plugins:
- ./vendor/bref/bref
resources:
Resources:
Cache:
Type: AWS::DynamoDB::Table
Properties:
TableName: laravel-bref-${self:provider.stage}-cache
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: key
AttributeType: S
KeySchema:
- AttributeName: key
KeyType: HASH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment