WHAT YOU'LL LEARN
  • how to apply different infrastructure settings per environment using Infra.Env.Is
  • how to read the current environment name inside extension logic using Infra.Env.useEnv

Overview
anchor

It’s common to want different infrastructure settings per environment — for example, enabling OpenSearch only in production, or applying different AWS tags per environment. Use Infra.Env.Is to conditionally apply any Infra.* configuration.

Configuration
anchor

webiny.config.tsx
import React from "react";
import { Infra } from "webiny/extensions";

export const Extensions = () => {
  return (
    <>
      <Infra.Env.Is env={["prod", "production", "staging"]}>
        <Infra.Aws.Tags tags={{ ENV: "production" }} />
        <Infra.OpenSearch enabled={true} />
      </Infra.Env.Is>

      <Infra.Env.Is env={"dev"}>
        <Infra.Aws.Tags tags={{ ENV: "non-production" }} />
        <Infra.OpenSearch enabled={false} />
      </Infra.Env.Is>
    </>
  );
};

Infra.Env.Is accepts either a single environment name string or an array of names. Any Infra.* component can be nested inside it.

Reading the Current Environment
anchor

Use Infra.Env.useEnv when you need the environment name as a value inside your own extension logic — for example, to build a resource name prefix dynamically:

webiny.config.tsx
import React from "react";
import { Infra } from "webiny/extensions";

const MyResourceNamePrefix = () => {
  const env = Infra.Env.useEnv();

  return <Infra.PulumiResourceNamePrefix prefix={`myapp-${env.name}-`} />;
};

export const Extensions = () => {
  return (
    <>
      <MyResourceNamePrefix />
    </>
  );
};

env.name returns the value passed via --env when running webiny deploy --env <name>.

Redeploying After Changes
anchor

After making changes, redeploy by running the webiny deploy command:

yarn webiny deploy

Use --env <name> to target a specific environment if needed.