![]() ![]() Download the latest version of WordPress, then extract the files there. Terraform automatically created a directory in the EFS filesystem ( /mnt/efs/roots/wp-lambda-$RANDOM_STRING), so cd to there first. Now that the filesystem is mounted, we can finally proceed to install WordPress. If you’re having trouble mounting the filesystem, double check the security groups and take a look at the User Guide. Log in to your EC2 server, then mount the EFS filesystem (replace fs-XXXXX with the value of the efs_file_system_id output): $ sudo -s Terraform created a security group for us (it’s in the efs_security_group_id output), so attach that to your EC2 instance. Mount EFS on the EC2 instance.įirst, we need to give the EC2 instance access to the EFS filesystem. Keep this window open, you’ll need it in the next step. If you don’t (or you already closed the window), you can always run terraform output. When the apply has finished, you should see some outputs. Terraform will ask you if you want to go ahead with the apply or not - look over the changes (the initial apply should not have any modifications or deletions), then respond yes. I manage a lot of AWS accounts, so I use the AWS_PROFILE environment variable. If you’re asked for your AWS credentials, Ctrl-C and try setting the authentication information via environment variables. Now, you’re ready to create the resources. If you want to use a custom domain name (instead of the default randomly-generated CloudFront domain name), set the acm_certificate_arn and domain_name variables as well. # An array of the Subnet IDs you listed in step 1. terraform-aws-wordpress-on-lambda-efsĬreate a file called, and put the following contents in to it: # An array of the Security Group IDs you listed in step 1. Install the amazon-efs-utils package to get ready for mounting the EFS volume.Īlso, while you’re in the console, note down the ID of a Security Group that allows access to RDS and the IDs of the private subnets to launch Lambda in. I’m working on getting the layer published in other regions, but in the meantime, use my fork of the php-lambda-layer to create your own in the region of your choosing. Lambda Layer that I’m using for this is only published in the us-west-2 region. If you’re following this step-by-step, be sure to choose the us-west-2 region. These steps assume you’re running this Terraform module standalone - if you want to run it in the context of an existing Terraform setup, prepare to adjust accordingly. An EC2 instance to perform the initial setup and install of WordPress.įor a list of the resources that Terraform will provision, take a look at the Resources page here.A MySQL database (I’m using MySQL on RDS using the smallest instance available).Terraform (the module uses v0.12 syntax, so you’ll need to use v0.12.).This is important because EFS connectivity requires Lambda to be set up in a VPC, but it won’t have Internet access by default. A VPC with Internet access through a NAT gateway or instance ( comparison).In this setup, Lambda is only used for running PHP - installing the initial WordPress files is done on an EC2 instance that has the EFS volume mounted. Tuning opcache to cache files in memory longer helped a lot.īecause EFS is synchronized across all the instances of Lambda, online updates, installs, and uploads work as expected. PHP is serving static assets bundled with WordPress as well, which adds to some latency (in this configuration, CloudFront is caching most of these files, however). ![]() The biggest performance bottleneck is the EFS filesystem, and there’s no getting around that. It’s not the best, but it isn’t bad, either. Here’s the Terraform module ( source code). This matches the existing infrastructure-as-code setup I use when I deploy infrastructure for clients. In addition, this time I’m using Terraform instead of SAM. Being able to use EFS completely changes the way WordPress works in Lambda (for the better!), so I felt it warranted a new blog post. ![]() I previously wrote a post about running WordPress on AWS Lambda, but it was before EFS support was announced (EFS is a managed network file system AWS provides). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |