Skip to main content

WordPress site in AWS Fargate with RDS DB backend

Deploys Wordpress in ECS Fargate with RDS backend.

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set aws-ts-wordpress-fargate-rds
cd pulumi-examples/aws-ts-wordpress-fargate-rds

This example serves a WordPress site in AWS ECS Fargate using an RDS MySQL Backend.

It leverages the following Pulumi concepts/constructs:

  • Component Resources: Allows one to create custom resources that encapsulate one’s best practices. In this example, component resource is used to define a “VPC” custom resource, a “Backend” custom resource that sets up the RDS DB, and a “Frontend” resource that sets up the ECS cluster and load balancer and tasks.
  • Other Providers: Beyond the providers for the various clouds and Kubernetes, etc, Pulumi allows one to create and manage non-cloud resources. In this case, the program uses the Random provider to create a random password if necessary.

This sample uses the following AWS products (and related Pulumi providers):

  • Amazon VPC: Used to set up a new virtual network in which the system is deployed.
  • Amazon RDS: A managed DB service used to provide the MySQL backend for WordPress.
  • Amazon ECS Fargate: A container service used to run the WordPress frontend.

There are no required configuration parameters for this project since the code will use defaults or generate values as needed - see the beginning of index.ts to see the defaults. However, you can override these defaults by using pulumi config to set the following values (e.g. pulumi config set serviceName my-wp-demo):

  • serviceName - This is used as a prefix for resources created by the Pulumi program.
  • dbName - The name of the MySQL DB created in RDS.
  • dbUser - The user created with access to the MySQL DB.
  • dbPassword - The password for the DB user. Be sure to use --secret if creating this config value (e.g. pulumi config set dbPassword --secret).

Prerequisites#

  1. Install Pulumi
  2. Configure AWS credentials
  3. Install Node.js

Deploying the example#

Note: some values in this example will be different from run to run.

  1. Create a new stack:

    Terminal window
    pulumi stack init dev
  2. Set the AWS region to deploy into:

    Terminal window
    pulumi config set aws:region us-west-2
  3. Install dependencies:

    Terminal window
    npm install
  4. Run pulumi up to preview and deploy changes. After the preview is shown you will be prompted if you want to continue or not. Note: If you set the dbPassword in the configuration as described above, you will not see the RandomPassword resource.

    Terminal window
    pulumi up
  5. The program outputs the following values:

    • DB Endpoint: This is the RDS DB endpoint. By default, the DB is deployed to disallow public access. This can be overriden in the resource declaration for the backend.
    • DB Password: This is managed as a secret. To see the value, you can use pulumi stack output --show-secrets.
    • DB User Name: The user name for accessing the DB.
    • ECS Cluster Name: The name of the ECS cluster created by the stack.
    • Web Service URL: This is a link to the load balancer fronting the WordPress container. Note: It may take a few minutes for AWS to complete deploying the service and so you may see a 503 error initially.

Cleaning up#

To clean up resources, destroy your stack and remove it:

Terminal window
pulumi destroy
pulumi stack rm

Troubleshooting#

503 error for the web service#

AWS can take a few minutes to complete deploying the WordPress container and connect the load balancer to the service. So you may see a 503 error for a few minutes right after launching the stack. You can see the status of the service by looking at the cluster in AWS.

Deployment speed#

Since the stack creates an RDS instance, ECS cluster, load balancer, ECS service, as well as other elements, the stack can take about 4-5 minutes to launch and become ready.

Related

The infrastructure as code platform for any cloud.