An ambitious ember-cli-deploy plugin for serving Ember FastBoot Applications entirely from within AWS Lambda/API Gateway (assets and all!).
API Gateway now supports the handling binary payloads, which means an end-to-end fastboot hosting solution can now be achieved through API gateway and Lambda without the use of S3 for serving static files. This is what this addon aims to achieve.
- You have ember-fastboot installed and configured within your Ember app.
- You have an AWS account setup.
- You have the AWS CLI installed and configured.
- Install the ember-cli-deploy addons
ember install ember-cli-deploy
ember install ember-cli-deploy-build
ember install ember-cli-deploy-fastboot-api-lambda
- Configure the deployment variables
// config/deploy.js
ENV['fastboot-api-lambda'] = {
accessKeyId: process.env.AWS_ACCESS_KEY_ID, // (Required) AWS accessKeyId (must have permission to deploy lambda functions)
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, // (Required) AWS secretAccessKey
lambdaFunction: 'my-ember-app', // (Required) Lambda functions name
region: 'us-east-1', // (Required) Region where lambda is deployed
fallbackPath: '/' // (optional) The route that will be attempted if the current route fails. i.e. doesn't exist, fails etc.
stringyExtensions: [ // (optional) The file extensions that will be treated as text and not binary. Defaults are shown. Any additional items will be concatenated to this list.
'html',
'css',
'js',
'json',
'xml',
'ico',
'txt',
'map'
],
validAssetPaths: [ // (optional) The assets paths that the lambda is explicitly allow serve. Defaults are shown. Any additional items will be concatenated to this list.
'/assets/',
'/robots.txt',
'/humans.txt',
'/crossdomain.xml',
'/sitemap.xml'
]
};
-
Create the lambda function
- Open the AWS Lambda console.
- Select the region that you defined in your deploy variables above.
- Create a blank lambda, with the name you defined in your deploy variables above.
- Handler =>
index.handler
. - Role =>
Create a custom role
. Give it a name and use the default policy document. - Memory =>
128
. - Timeout =>
30 seconds
.
- Handler =>
- Select
Next
and then selectCreate function
.
-
Create the API Gateway Proxy
- Open the AWS API Gateway console.
- Select the region that you defined in your deploy variables above.
- Select
New API
and give it a name - Select Binary Support. Click
Edit
. Add*/*
and clickSave
. - Create proxy method:
- Under resources, click
/
, then clickActions => Create Method
. SelectAny
. - Click the
Any label
, choose Integration typelambda
, check theUse Lambda Proxy integration
checkbox, and finally select your lambda function's region and name.
- Under resources, click
- Create proxy resource:
- Under resources, click
/
, then clickActions => Create Resource
. SelectAny
. - Select
Configure as proxy resource
, and selectEnable API Gateway CORS
. - Select Integration type
Lambda Function Proxy
, and finally select your lambda function's region and name.
- Under resources, click
- Under resources, click
Actions => Deploy API
. Select a new stage and give it the namefastboot
. HitDeploy
. You will now see theInvoke URL
. This is where you site will be hosted.
-
Ember Application
- The
rootURL
must match the stage name you selected when creating the api gateway. Otherwise thelink-to
helper wont work.
// config/environment.js var ENV = { rootURL: '/fastboot/' }
- The
-
Configuration is done! 🎉
Is as simple as going:
ember deploy production --activate --verbose=true
Just a word of warning.. just because this architecture is possible, doesn't make it the optimal for all use-cases. Lambda functions suffer from a cold start delay, which can make response times unpredictable.
Feel free to make a pull request if you would like your site added to the list!
ember-cli-deploy-fastboot-lambda for providing the base upload logic.
For more information on using ember-cli, visit http://www.ember-cli.com/.
For more information on using ember-cli-deploy, visit https://github.com/ember-cli-deploy/ember-cli-deploy.