Deploying Strapi to AWS with Flightcontrol
Strapi is an open-source headless Content Management System (CMS) that enables developers to build projects faster by providing a customizable API and allowing them to use their favorite tools. This tutorial will provide detailed steps on how to deploy your Strapi project on Flightcontrol.
Prerequisites
Make sure you’ve completed the following before proceeding with this guide:
- Get started with Strapi
- Create a Flightcontrol account
- Create an AWS account
- Create a GitHub account
Configuration Options
Follow these steps to deploy your Strapi application using the GUI configuration type:
- Select a configuration type of “GUI”
- Select an environment
- Select a service
- Strapi requires that the following environment variables be set on Flightcontrol for the remote instance:
JWT_SECRET
ADMIN_JWT_SECRET
API_TOKEN_SALT
APP_KEYS
TRANSFER_TOKEN_SALT
- Adjust configuration as needed
- Click “Create Project” and complete any required steps (like linking your AWS account and adding the required environment variables)
Environment Variable Definitions
Variable | Description | Example |
---|---|---|
JWT_SECRET | This is used to set the secret key for JSON Web Token (JWT) authentication. It is often used for authentication and authorization purposes. | JWT_SECRET = tH0iS19ktGyVxJfbQc6TIT |
ADMIN_JWT_SECRET | This is used to set the secret key specifically for the administration panel’s JSON Web Token (JWT) authentication. | ADMIN_JWT_SECRET = 5Mt/XPHdS0IBP21wCXo4OG |
API_TOKEN_SALT | This is used to define a secret salt value that is used when generating API tokens.API tokens are used for authentication and authorization purposes in Strapi’s API endpoints. | API_TOKEN_SALT = VdANubbaOqpys5wROHz/tA |
APP_KEYS | This is used to encrypt and decrypt sensitive data stored in the database or transmitted over the network. They ensure that only authorized parties can access encrypted data. | APP_KEYS = VdAMubba9qpys3wKPHx/tA |
TRANSFER_TOKEN_SALT | This serves as an encrypted salt for generating transfer tokens | TRANSFER_TOKEN_SALT = VdAMu+bba9qpys3wKPHTtA |
DATABASE_CLIENT | This is used to specify the type of database client that Strapi should use to connect to your database. | DATABASE_FILENAME = sqlite |
DATABASE_FILENAME | This is used to specify the filename of the database file used by Strapi. | DATABASE_FILENAME = .tmp/data.db |
Support Image Uploads With Cloudinary
Strapi CMS requires a shared storage to upload images and other files. Flightcontrol deploys to containers, during this process there is a risk that file systems might get erased on re-deploys. Cloudinary fixes this problem by providing a cloud-based storage system which allows users to create, manage, and deliver dynamic visual experiences for websites and apps.
Installation
npm install @strapi/provider-upload-cloudinary
Configuration
-
provider
describes the name of the provider -
providerOptions
is used when configuring the provider (ex: cloudinary.config). Complete list of options -
actionOptions
allows users to customize the behavior of file uploads and define specific settings for different actions. Here is a complete list of upload/ uploadStream options and delete options
For information about installing and using a provider visit documentation about using a provider. To learn more about how Strapi utilizes environment variables, please refer to the documentation about environment variables.
Example
module.exports = ({env}) => ({
// ...
upload: {
config: {
provider: "cloudinary",
providerOptions: {
cloud_name: env("CLOUDINARY_NAME"),
api_key: env("CLOUDINARY_KEY"),
api_secret: env("CLOUDINARY_SECRET"),
},
actionOptions: {
upload: {},
uploadStream: {},
delete: {},
},
},
},
// ...
})
Security Middleware Configuration
In order to make changes to the default settings in the Strapi Security Middleware, it is necessary to modify the contentSecurityPolicy
settings to see thumbnail previews in the Media Library properly. The strapi::security
string should be replaced with the object below, as explained in the middleware configuration documentation.
module.exports = [
// ...
{
name: "strapi::security",
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
"connect-src": ["'self'", "https:"],
"img-src": ["'self'", "data:", "blob:", "dl.airtable.com", "res.cloudinary.com"],
"media-src": ["'self'", "data:", "blob:", "dl.airtable.com", "res.cloudinary.com"],
upgradeInsecureRequests: null,
},
},
},
},
// ...
]
Setting Cloudinary Configurations
- Create an account https://cloudinary.com/
- Navigate to Getting Started
- Set up the work environment according to the framework you are using
- Copy the Cloudinary Config
- Paste the new variables in your
.env
file.
Note
The naming convention in the environment configuration in the Flightcontrol Dashboard has to match with the keys under providerOptions
in ./config/plugins.js
CLOUDINARY_NAME=********
CLOUDINARY_KEY=**********
CLOUDINARY_SECRET=***********
Support Image Uploads With Amazon S3
Follow instructions at How to Set up Amazon S3 Upload Provider Plugin for Your Strapi App
Conclusion
In this tutorial, you deployed a Strapi project using the Flightcontrol Dashboard or flightcontrol.json
file. You also learned how to add Cloudinary and AWS S3 Bucket plugins to your Strapi project.