Skip to content
GitHubXDiscord

Environment

The Environment resource lets you manage AWS ElasticBeanstalk Environments to deploy and scale web applications and services.

Create a basic ElasticBeanstalk Environment with required properties and one optional description.

import AWS from "alchemy/aws/control";
const elasticBeanstalkEnv = await AWS.ElasticBeanstalk.Environment("myAppEnvironment", {
ApplicationName: "MyWebApp",
PlatformArn: "arn:aws:elasticbeanstalk:us-west-2::platform/Java 8 running on 64bit Amazon Linux/2.9.0",
Description: "My Elastic Beanstalk environment for the web application"
});

Configure an ElasticBeanstalk Environment with additional options such as custom CNAME prefix and environment tier.

const advancedElasticBeanstalkEnv = await AWS.ElasticBeanstalk.Environment("advancedEnv", {
ApplicationName: "MyWebApp",
PlatformArn: "arn:aws:elasticbeanstalk:us-west-2::platform/Node.js 14 running on 64bit Amazon Linux/2.7.2",
CNAMEPrefix: "mywebapp",
Tier: {
Name: "WebServer",
Type: "Standard",
Version: "1.0"
},
OptionSettings: [
{
Namespace: "aws:autoscaling:launchconfiguration",
OptionName: "InstanceType",
Value: "t2.micro"
},
{
Namespace: "aws:elasticbeanstalk:environment",
OptionName: "EnvironmentType",
Value: "LoadBalanced"
}
]
});

Create an environment with tags for better resource organization and management.

const taggedElasticBeanstalkEnv = await AWS.ElasticBeanstalk.Environment("taggedEnv", {
ApplicationName: "MyWebApp",
PlatformArn: "arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.4 running on 64bit Amazon Linux/2.9.0",
Tags: [
{
Key: "Project",
Value: "WebApp2023"
},
{
Key: "Owner",
Value: "DevTeam"
}
]
});

Demonstrate an environment configured with custom option settings for monitoring and scaling.

const customOptionsEnv = await AWS.ElasticBeanstalk.Environment("customOptionsEnv", {
ApplicationName: "MyWebApp",
PlatformArn: "arn:aws:elasticbeanstalk:us-west-2::platform/DotNet Core 3.1 running on 64bit Amazon Linux/2.3.4",
OptionSettings: [
{
Namespace: "aws:elasticbeanstalk:application",
OptionName: "ApplicationHealthcheckURL",
Value: "/health"
},
{
Namespace: "aws:elasticbeanstalk:environment",
OptionName: "ServiceRole",
Value: "arn:aws:iam::123456789012:role/elasticbeanstalk-service-role"
}
]
});