Warning
You're browsing the documentation for an old version of Webiny. Consider upgrading your project to Webiny 5.39.x.
What you’ll learn
  • how to modify cloud infrastructure resources deployed by Webiny

Overview
anchor

Users use the webiny deploy command to deploy their Webiny project, into an environment of their choice. During the deployment, apart from building the actual project applications, the command also ensures that a set of required cloud infrastructure resources is deployed.

To deploy necessary cloud infrastructure resources, by default, Webiny relies on Pulumi, a modern infrastructure as code framework. Find out more in the following IaC with Pulumi key topic.

Read more about the cloud infrastructure resources that get deployed into your AWS account in our Cloud Infrastructure key topics section.

And although the cloud infrastructure resources that Webiny deploys are already configured in the best possible manner, there are still cases where some modifications might be needed. In some cases even, the deployed cloud infrastructure needs to be expanded by introducing additional resources into the mix.

To do this, we rely on four webiny.application.ts configuration files, located in each of the four project application folders in every Webiny project:

  1. Core (apps/core/webiny.application.tsexternal link)
  2. API (apps/api/webiny.application.tsexternal link)
  3. Admin (apps/admin/webiny.application.tsexternal link)
  4. Website (apps/website/webiny.application.tsexternal link)

Which webiny.application.ts config file needs to be changed depends on the nature of the change that needs to be made.

For example, let’s imagine we want to adjust the configuration of the Amazon S3 bucket that’s deployed for storing files uploaded via Webiny File Manager. Since this bucket is deployed as part of the Core project application, naturally, we’d want to apply changes via the apps/core/webiny.application.tsexternal link configuration file.

The following example demonstrates how the bucket can be adjusted to enable object versioningexternal link, which essentially enables keeping multiple variants of an object in the same bucket:

apps/core/webiny.application.ts

As we can see, using the pulumi parameter, we’ve passed a relatively simple callback function that enables object versioning in two steps:

  1. references the relevant bucket via the fileManagerBucket const
  2. uses the reference to enable bucket versioning, via the fileManagerBucket.config.versioning

Once the above code change has been made, all that is left to do is a redeploy by running the following command:

With the deployment successfully completed, the object versioning should be enabled for your project (for all files that are uploaded via Webiny File Manager).

When redeploying, make sure to redeploy the project application within which the changes were actually made. In the above example, we’ve made changes within the Core application’s webiny.application.ts file, meaning the Core application needs to be redeployed in order to actually see the changes.

Additional Examples
anchor

In this section, we cover a couple of additional examples of modifying cloud infrastructure resources that get deployed with every Webiny project.

Tagging Cloud Infrastructure Resources
anchor

The following example shows how to apply tags to all cloud infrastructure resources deployed as part of the Core project application. Note that the same approach can be used for all four applications.

apps/core/webiny.application.ts

Note that the tagResources function applies tags only to resources that can actually be tagged. Full list of resources can be found hereexternal link.

Pulumi Resource Name Prefixes
anchor

By default, all cloud infrastructure resources deployed by Webiny are prefixed with the wby- prefix. If needed, this prefix can be changed via the pulumiResourceNamePrefix parameter, via the four webiny.application.ts configuration files, located in each of the four project application folders in every Webiny project:

  1. Core (apps/core/webiny.application.tsexternal link)
  2. API (apps/api/webiny.application.tsexternal link)
  3. Admin (apps/admin/webiny.application.tsexternal link)
  4. Website (apps/website/webiny.application.tsexternal link)

For example:

apps/core/webiny.application.ts

Note that, in the above example, we’ve adjusted the prefix within the Core application’s webiny.application.tsexternal link configuration file, but the same works with other applications as well.

Furthermore, note that the prefix can also be assigned dynamically, via a callback function. The following example shows how we can dynamically assign the prefix based on the environment name.

apps/core/webiny.application.ts

Retrieving the Deployment Environment
anchor

Upon running the webiny deploy command, we specify the environment into which we want to deploy our project (or a specific project application). In more complex cases, we may need to retrieve the environment in order to conditionally apply different configuration to our cloud infrastructure.

The following example shows how we can read the environment into which the application is being deployed.

apps/core/webiny.application.ts

Note that, in the above example, we’ve made the changes within the Core application’s webiny.application.tsexternal link configuration file, but the same works with other applications as well.

Furthermore, this approach can also be used with other parameters, not just pulumi. For example, we can use the same approach when defining the resource name prefix.

apps/core/webiny.application.ts

Defining Multiple Production Environments
anchor

Upon running the webiny deploy command, when prod is passed as the environment name, a Webiny project is deployed in the so-called production deployment modeexternal link.

On order to use the production deployment mode for environments other than prod, we can use the productionEnvironments parameter. The following example shows how we can use the production mode for the staging environment:

apps/core/webiny.application.ts

Note that when specifying additional production environments, they should be specified across all project applications, meaning:

  1. Core (apps/core/webiny.application.tsexternal link)
  2. API (apps/api/webiny.application.tsexternal link)
  3. Admin (apps/admin/webiny.application.tsexternal link)
  4. Website (apps/website/webiny.application.tsexternal link)

Modifying AWS IAM Roles
anchor

The following example demonstrates how we can modify the default AWS IAM role that’s assigned to the AWS Lambda function that represents your GraphQL API (the one accessed via the https://xyz.cloudfront.net/graphql URL).

To learn more about the default GraphQL API and differences between it and the Headless CMS GraphQL API, please check out the Introduction section of the Extend GraphQL API article.

If you want to learn more about the main GraphQL API and how it works on the cloud infrastructure level, check out the GraphQL Requests page of the Cloud Infrastructure - API key topics section.

Adding AWS Lambda Functions
anchor

Creating a Cron Job
anchor

In this example, we introduce a new AWS Lambda function which is triggered once every minute.

Note that the code assumes the AWS Lambda function’s code is located in the apps/api/myCronJob folder. For the full code, please check our webiny-examplesexternal link GitHub repository.

apps/api/webiny.application.ts

Adjusting Amazon Elasticsearch (OpenSearch) Configuration
anchor

Amazon Elasticsearch (OpenSearch) is deployed as part of the Core project application. In order to make changes to it, we need to make changes in the apps/core/webiny.application.ts configuration file.

apps/core/webiny.application.ts

Adjusting Amazon CloudFront Distribution Configuration
anchor

A single Webiny project deploys four Amazon CloudFront distributions: one for API, one for Admin, and two for Website project application.

Therefore, if there’s a need to apply a change across all distributions, the change needs to be applied via the following three webiny.application.ts configuration files:

  1. apps/api/webiny.application.tsexternal link
  2. apps/admin/webiny.application.tsexternal link
  3. apps/website/webiny.application.tsexternal link

The following example demonstrates how we can adjust the TLS version for the distribution that’s deployed as part of the API project application.

apps/api/webiny.application.ts