Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Latest commit

 

History

History
1823 lines (1149 loc) · 79.5 KB

API.md

File metadata and controls

1823 lines (1149 loc) · 79.5 KB

Next.js Standalone ECS Site

WARNING

Leaving this here in case someone can use it as a jumping off point, but the copying method used breaks at scale. Ends up being a race between the first container and when the others start up, and they can break one another. Recommend a different strategy.

NPM Package

View on Construct Hub

Have a very simple use case for Next.js? Perhaps akin to what you would use a SPA (single page app) for? Check out cdk-nextjs-export-s3-dynamic-routing.

Deploy a Next.js site to AWS ECS supporting all version 13 features, including properly functioning, efficient Incremental Static Regeneration and Image Optimization.

This construct employs AWS EFS to share the .next directory between containers, as is recommended by Vercel.

Getting Started

A full example including custom domain, SSL, and Cloudfront is in the /example folder. This construct can also be used with only a VPC and ALB as well, with no caching or custom domain.

You can see the requirements for this construct there, but they are also spelled out in detail below.

The full API of this construct is available in the API.md file.

Requirements

next.config.?s

  • output must be set to standalone. This is what Vercel recommends for Docker based deployments.
  • experimental.isrMemoryCacheSize must be set to zero. Without this, you can get odd responses when using ISR and having multiple containers.

Scripts

Some minimal scripts that handle moving files around when a new build is created are required. They are available in the docker folder.

Dockerfile

The following should be inserted during the final steps, just after the standalone folder is copied.

# Additions from NextjsStandaloneEcsSite
# We use curl to run the health check on the container
RUN apk add --update curl
# Copy our scripts to the root of the container
COPY --from=builder --chown=nextjs:nodejs app/docker ./
# Move the build out of the way of our .next folder shared across containers
RUN mv ./.next ./.next.currentBuild
RUN mkdir -p ./.next
RUN chown nextjs:nodejs ./.next
# End additions from NextjsStandaloneEcsSite

In addition, the final line in the Dockerfile should be changed to:

ENTRYPOINT ["sh","./startup.sh"]

Instead of any CMD or existing ENTRYPOINT. You can add to startup.sh if you need to run additional commands before the container starts.

API Reference

Constructs

NextjsStandaloneEcsSite

This is a standalone ECS site that uses Next.js and is deployed to AWS ECS.

It employs AWS EFS to share the .next directory between containers to facilitate proper Incremental Static Regeneration.

This construct can also be used with only a VPC and ALB, with no caching or custom domain, or behind a Route53 domain and Cloudfront.

Initializers

import { NextjsStandaloneEcsSite } from 'cdk-nextjs-standalone-ecs'

new NextjsStandaloneEcsSite(scope: Construct, id: string, props: NextjsStandaloneEcsSiteProps)
Name Type Description
scope constructs.Construct No description.
id string No description.
props NextjsStandaloneEcsSiteProps No description.

scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

propsRequired

Methods

Name Description
toString Returns a string representation of this construct.

toString
public toString(): string

Returns a string representation of this construct.

Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
import { NextjsStandaloneEcsSite } from 'cdk-nextjs-standalone-ecs'

NextjsStandaloneEcsSite.isConstruct(x: any)

Checks if x is a construct.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.
cluster aws-cdk-lib.aws_ecs.Cluster No description.
container aws-cdk-lib.aws_ecs.ContainerDefinition No description.
dockerImageAsset aws-cdk-lib.aws_ecr_assets.DockerImageAsset No description.
fileSystem aws-cdk-lib.aws_efs.FileSystem No description.
fileSystemAccessPoint aws-cdk-lib.aws_efs.AccessPoint No description.
service aws-cdk-lib.aws_ecs.FargateService No description.
taskDefinition aws-cdk-lib.aws_ecs.TaskDefinition No description.
volume aws-cdk-lib.aws_ecs.Volume No description.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


clusterRequired
public readonly cluster: Cluster;
  • Type: aws-cdk-lib.aws_ecs.Cluster

containerRequired
public readonly container: ContainerDefinition;
  • Type: aws-cdk-lib.aws_ecs.ContainerDefinition

dockerImageAssetRequired
public readonly dockerImageAsset: DockerImageAsset;
  • Type: aws-cdk-lib.aws_ecr_assets.DockerImageAsset

fileSystemRequired
public readonly fileSystem: FileSystem;
  • Type: aws-cdk-lib.aws_efs.FileSystem

fileSystemAccessPointRequired
public readonly fileSystemAccessPoint: AccessPoint;
  • Type: aws-cdk-lib.aws_efs.AccessPoint

serviceRequired
public readonly service: FargateService;
  • Type: aws-cdk-lib.aws_ecs.FargateService

taskDefinitionRequired
public readonly taskDefinition: TaskDefinition;
  • Type: aws-cdk-lib.aws_ecs.TaskDefinition

volumeRequired
public readonly volume: Volume;
  • Type: aws-cdk-lib.aws_ecs.Volume

Constants

Name Type Description
RECOMMENDED_CACHE_POLICY aws-cdk-lib.aws_cloudfront.CachePolicyProps Included for convenience, this cache policy is very similar to Amplify's cache policy, but with a higher maxTtl.

RECOMMENDED_CACHE_POLICYRequired
public readonly RECOMMENDED_CACHE_POLICY: CachePolicyProps;
  • Type: aws-cdk-lib.aws_cloudfront.CachePolicyProps

Included for convenience, this cache policy is very similar to Amplify's cache policy, but with a higher maxTtl.


Structs

NextjsStandaloneEcsBaseServiceOptions

ecs.BaseServiceOptions Omit cluster.

Initializer

import { NextjsStandaloneEcsBaseServiceOptions } from 'cdk-nextjs-standalone-ecs'

const nextjsStandaloneEcsBaseServiceOptions: NextjsStandaloneEcsBaseServiceOptions = { ... }

Properties

Name Type Description
capacityProviderStrategies aws-cdk-lib.aws_ecs.CapacityProviderStrategy[] A list of Capacity Provider strategies used to place a service.
circuitBreaker aws-cdk-lib.aws_ecs.DeploymentCircuitBreaker Whether to enable the deployment circuit breaker.
cloudMapOptions aws-cdk-lib.aws_ecs.CloudMapOptions The options for configuring an Amazon ECS service to use service discovery.
deploymentController aws-cdk-lib.aws_ecs.DeploymentController Specifies which deployment controller to use for the service.
desiredCount number The desired number of instantiations of the task definition to keep running on the service.
enableECSManagedTags boolean Specifies whether to enable Amazon ECS managed tags for the tasks within the service.
enableExecuteCommand boolean Whether to enable the ability to execute into a container.
healthCheckGracePeriod aws-cdk-lib.Duration The period of time, in seconds, that the Amazon ECS service scheduler ignores unhealthy Elastic Load Balancing target health checks after a task has first started.
maxHealthyPercent number The maximum number of tasks, specified as a percentage of the Amazon ECS service's DesiredCount value, that can run in a service during a deployment.
minHealthyPercent number The minimum number of tasks, specified as a percentage of the Amazon ECS service's DesiredCount value, that must continue to run and remain healthy during a deployment.
propagateTags aws-cdk-lib.aws_ecs.PropagatedTagSource Specifies whether to propagate the tags from the task definition or the service to the tasks in the service.
serviceConnectConfiguration aws-cdk-lib.aws_ecs.ServiceConnectProps Configuration for Service Connect.
serviceName string The name of the service.

capacityProviderStrategiesOptional
public readonly capacityProviderStrategies: CapacityProviderStrategy[];
  • Type: aws-cdk-lib.aws_ecs.CapacityProviderStrategy[]
  • Default: undefined

A list of Capacity Provider strategies used to place a service.


circuitBreakerOptional
public readonly circuitBreaker: DeploymentCircuitBreaker;
  • Type: aws-cdk-lib.aws_ecs.DeploymentCircuitBreaker
  • Default: disabled

Whether to enable the deployment circuit breaker.

If this property is defined, circuit breaker will be implicitly enabled.


cloudMapOptionsOptional
public readonly cloudMapOptions: CloudMapOptions;
  • Type: aws-cdk-lib.aws_ecs.CloudMapOptions
  • Default: AWS Cloud Map service discovery is not enabled.

The options for configuring an Amazon ECS service to use service discovery.


deploymentControllerOptional
public readonly deploymentController: DeploymentController;
  • Type: aws-cdk-lib.aws_ecs.DeploymentController
  • Default: Rolling update (ECS)

Specifies which deployment controller to use for the service.

For more information, see Amazon ECS Deployment Types


desiredCountOptional
public readonly desiredCount: number;
  • Type: number
  • Default: When creating the service, default is 1; when updating the service, default uses the current task number.

The desired number of instantiations of the task definition to keep running on the service.


enableECSManagedTagsOptional
public readonly enableECSManagedTags: boolean;
  • Type: boolean
  • Default: false

Specifies whether to enable Amazon ECS managed tags for the tasks within the service.

For more information, see Tagging Your Amazon ECS Resources


enableExecuteCommandOptional
public readonly enableExecuteCommand: boolean;
  • Type: boolean
  • Default: undefined

Whether to enable the ability to execute into a container.


healthCheckGracePeriodOptional
public readonly healthCheckGracePeriod: Duration;
  • Type: aws-cdk-lib.Duration
  • Default: defaults to 60 seconds if at least one load balancer is in-use and it is not already set

The period of time, in seconds, that the Amazon ECS service scheduler ignores unhealthy Elastic Load Balancing target health checks after a task has first started.


maxHealthyPercentOptional
public readonly maxHealthyPercent: number;
  • Type: number
  • Default: 100 if daemon, otherwise 200

The maximum number of tasks, specified as a percentage of the Amazon ECS service's DesiredCount value, that can run in a service during a deployment.


minHealthyPercentOptional
public readonly minHealthyPercent: number;
  • Type: number
  • Default: 0 if daemon, otherwise 50

The minimum number of tasks, specified as a percentage of the Amazon ECS service's DesiredCount value, that must continue to run and remain healthy during a deployment.


propagateTagsOptional
public readonly propagateTags: PropagatedTagSource;
  • Type: aws-cdk-lib.aws_ecs.PropagatedTagSource
  • Default: PropagatedTagSource.NONE

Specifies whether to propagate the tags from the task definition or the service to the tasks in the service.

Valid values are: PropagatedTagSource.SERVICE, PropagatedTagSource.TASK_DEFINITION or PropagatedTagSource.NONE


serviceConnectConfigurationOptional
public readonly serviceConnectConfiguration: ServiceConnectProps;
  • Type: aws-cdk-lib.aws_ecs.ServiceConnectProps
  • Default: No ports are advertised via Service Connect on this service, and the service cannot make requests to other services via Service Connect.

Configuration for Service Connect.


serviceNameOptional
public readonly serviceName: string;
  • Type: string
  • Default: CloudFormation-generated name.

The name of the service.


NextjsStandaloneEcsClusterProps

ecs.ClusterProps Omit vpc.

Initializer

import { NextjsStandaloneEcsClusterProps } from 'cdk-nextjs-standalone-ecs'

const nextjsStandaloneEcsClusterProps: NextjsStandaloneEcsClusterProps = { ... }

Properties

Name Type Description
capacity aws-cdk-lib.aws_ecs.AddCapacityOptions The ec2 capacity to add to the cluster.
clusterName string The name for the cluster.
containerInsights boolean If true CloudWatch Container Insights will be enabled for the cluster.
defaultCloudMapNamespace aws-cdk-lib.aws_ecs.CloudMapNamespaceOptions The service discovery namespace created in this cluster.
enableFargateCapacityProviders boolean Whether to enable Fargate Capacity Providers.
executeCommandConfiguration aws-cdk-lib.aws_ecs.ExecuteCommandConfiguration The execute command configuration for the cluster.

capacityOptional
public readonly capacity: AddCapacityOptions;
  • Type: aws-cdk-lib.aws_ecs.AddCapacityOptions
  • Default: no EC2 capacity will be added, you can use addCapacity to add capacity later.

The ec2 capacity to add to the cluster.


clusterNameOptional
public readonly clusterName: string;
  • Type: string
  • Default: CloudFormation-generated name

The name for the cluster.


containerInsightsOptional
public readonly containerInsights: boolean;
  • Type: boolean
  • Default: Container Insights will be disabled for this cluster.

If true CloudWatch Container Insights will be enabled for the cluster.


defaultCloudMapNamespaceOptional
public readonly defaultCloudMapNamespace: CloudMapNamespaceOptions;
  • Type: aws-cdk-lib.aws_ecs.CloudMapNamespaceOptions
  • Default: no service discovery namespace created, you can use addDefaultCloudMapNamespace to add a default service discovery namespace later.

The service discovery namespace created in this cluster.


enableFargateCapacityProvidersOptional
public readonly enableFargateCapacityProviders: boolean;
  • Type: boolean
  • Default: false

Whether to enable Fargate Capacity Providers.


executeCommandConfigurationOptional
public readonly executeCommandConfiguration: ExecuteCommandConfiguration;
  • Type: aws-cdk-lib.aws_ecs.ExecuteCommandConfiguration
  • Default: no configuration will be provided.

The execute command configuration for the cluster.


NextjsStandaloneEcsContainerDefinitionOptions

ecs.ContainerDefinitionOptions Omit image.

Initializer

import { NextjsStandaloneEcsContainerDefinitionOptions } from 'cdk-nextjs-standalone-ecs'

const nextjsStandaloneEcsContainerDefinitionOptions: NextjsStandaloneEcsContainerDefinitionOptions = { ... }

Properties

Name Type Description
command string[] The command that is passed to the container.
containerName string The name of the container.
cpu number The minimum number of CPU units to reserve for the container.
disableNetworking boolean Specifies whether networking is disabled within the container.
dnsSearchDomains string[] A list of DNS search domains that are presented to the container.
dnsServers string[] A list of DNS servers that are presented to the container.
dockerLabels {[ key: string ]: string} A key/value map of labels to add to the container.
dockerSecurityOptions string[] A list of strings to provide custom labels for SELinux and AppArmor multi-level security systems.
entryPoint string[] The ENTRYPOINT value to pass to the container.
environment {[ key: string ]: string} The environment variables to pass to the container.
environmentFiles aws-cdk-lib.aws_ecs.EnvironmentFile[] The environment files to pass to the container.
essential boolean Specifies whether the container is marked essential.
extraHosts {[ key: string ]: string} A list of hostnames and IP address mappings to append to the /etc/hosts file on the container.
gpuCount number The number of GPUs assigned to the container.
healthCheck aws-cdk-lib.aws_ecs.HealthCheck The health check command and associated configuration parameters for the container.
hostname string The hostname to use for your container.
inferenceAcceleratorResources string[] The inference accelerators referenced by the container.
linuxParameters aws-cdk-lib.aws_ecs.LinuxParameters Linux-specific modifications that are applied to the container, such as Linux kernel capabilities.
logging aws-cdk-lib.aws_ecs.LogDriver The log configuration specification for the container.
memoryLimitMiB number The amount (in MiB) of memory to present to the container.
memoryReservationMiB number The soft limit (in MiB) of memory to reserve for the container.
portMappings aws-cdk-lib.aws_ecs.PortMapping[] The port mappings to add to the container definition.
privileged boolean Specifies whether the container is marked as privileged.
pseudoTerminal boolean When this parameter is true, a TTY is allocated.
readonlyRootFilesystem boolean When this parameter is true, the container is given read-only access to its root file system.
secrets {[ key: string ]: aws-cdk-lib.aws_ecs.Secret} The secret environment variables to pass to the container.
startTimeout aws-cdk-lib.Duration Time duration (in seconds) to wait before giving up on resolving dependencies for a container.
stopTimeout aws-cdk-lib.Duration Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own.
systemControls aws-cdk-lib.aws_ecs.SystemControl[] A list of namespaced kernel parameters to set in the container.
ulimits aws-cdk-lib.aws_ecs.Ulimit[] An array of ulimits to set in the container.
user string The user name to use inside the container.
workingDirectory string The working directory in which to run commands inside the container.

commandOptional
public readonly command: string[];
  • Type: string[]
  • Default: CMD value built into container image.

The command that is passed to the container.

If you provide a shell command as a single string, you have to quote command-line arguments.


containerNameOptional
public readonly containerName: string;
  • Type: string
  • Default: id of node associated with ContainerDefinition.

The name of the container.


cpuOptional
public readonly cpu: number;
  • Type: number
  • Default: No minimum CPU units reserved.

The minimum number of CPU units to reserve for the container.


disableNetworkingOptional
public readonly disableNetworking: boolean;
  • Type: boolean
  • Default: false

Specifies whether networking is disabled within the container.

When this parameter is true, networking is disabled within the container.


dnsSearchDomainsOptional
public readonly dnsSearchDomains: string[];
  • Type: string[]
  • Default: No search domains.

A list of DNS search domains that are presented to the container.


dnsServersOptional
public readonly dnsServers: string[];
  • Type: string[]
  • Default: Default DNS servers.

A list of DNS servers that are presented to the container.


dockerLabelsOptional
public readonly dockerLabels: {[ key: string ]: string};
  • Type: {[ key: string ]: string}
  • Default: No labels.

A key/value map of labels to add to the container.


dockerSecurityOptionsOptional
public readonly dockerSecurityOptions: string[];
  • Type: string[]
  • Default: No security labels.

A list of strings to provide custom labels for SELinux and AppArmor multi-level security systems.


entryPointOptional
public readonly entryPoint: string[];
  • Type: string[]
  • Default: Entry point configured in container.

The ENTRYPOINT value to pass to the container.

https://docs.docker.com/engine/reference/builder/#entrypoint


environmentOptional
public readonly environment: {[ key: string ]: string};
  • Type: {[ key: string ]: string}
  • Default: No environment variables.

The environment variables to pass to the container.


environmentFilesOptional
public readonly environmentFiles: EnvironmentFile[];
  • Type: aws-cdk-lib.aws_ecs.EnvironmentFile[]
  • Default: No environment files.

The environment files to pass to the container.

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/taskdef-envfiles.html


essentialOptional
public readonly essential: boolean;
  • Type: boolean
  • Default: true

Specifies whether the container is marked essential.

If the essential parameter of a container is marked as true, and that container fails or stops for any reason, all other containers that are part of the task are stopped. If the essential parameter of a container is marked as false, then its failure does not affect the rest of the containers in a task. All tasks must have at least one essential container.

If this parameter is omitted, a container is assumed to be essential.


extraHostsOptional
public readonly extraHosts: {[ key: string ]: string};
  • Type: {[ key: string ]: string}
  • Default: No extra hosts.

A list of hostnames and IP address mappings to append to the /etc/hosts file on the container.


gpuCountOptional
public readonly gpuCount: number;
  • Type: number
  • Default: No GPUs assigned.

The number of GPUs assigned to the container.


healthCheckOptional
public readonly healthCheck: HealthCheck;
  • Type: aws-cdk-lib.aws_ecs.HealthCheck
  • Default: Health check configuration from container.

The health check command and associated configuration parameters for the container.


hostnameOptional
public readonly hostname: string;
  • Type: string
  • Default: Automatic hostname.

The hostname to use for your container.


inferenceAcceleratorResourcesOptional
public readonly inferenceAcceleratorResources: string[];
  • Type: string[]
  • Default: No inference accelerators assigned.

The inference accelerators referenced by the container.


linuxParametersOptional
public readonly linuxParameters: LinuxParameters;
  • Type: aws-cdk-lib.aws_ecs.LinuxParameters
  • Default: No Linux parameters.

Linux-specific modifications that are applied to the container, such as Linux kernel capabilities.

For more information see KernelCapabilities.


loggingOptional
public readonly logging: LogDriver;
  • Type: aws-cdk-lib.aws_ecs.LogDriver
  • Default: Containers use the same logging driver that the Docker daemon uses.

The log configuration specification for the container.


memoryLimitMiBOptional
public readonly memoryLimitMiB: number;
  • Type: number
  • Default: No memory limit.

The amount (in MiB) of memory to present to the container.

If your container attempts to exceed the allocated memory, the container is terminated.

At least one of memoryLimitMiB and memoryReservationMiB is required for non-Fargate services.


memoryReservationMiBOptional
public readonly memoryReservationMiB: number;
  • Type: number
  • Default: No memory reserved.

The soft limit (in MiB) of memory to reserve for the container.

When system memory is under heavy contention, Docker attempts to keep the container memory to this soft limit. However, your container can consume more memory when it needs to, up to either the hard limit specified with the memory parameter (if applicable), or all of the available memory on the container instance, whichever comes first.

At least one of memoryLimitMiB and memoryReservationMiB is required for non-Fargate services.


portMappingsOptional
public readonly portMappings: PortMapping[];
  • Type: aws-cdk-lib.aws_ecs.PortMapping[]
  • Default: No ports are mapped.

The port mappings to add to the container definition.


privilegedOptional
public readonly privileged: boolean;
  • Type: boolean
  • Default: false

Specifies whether the container is marked as privileged.

When this parameter is true, the container is given elevated privileges on the host container instance (similar to the root user).


pseudoTerminalOptional
public readonly pseudoTerminal: boolean;
  • Type: boolean
  • Default: false

When this parameter is true, a TTY is allocated.

This parameter maps to Tty in the "Create a container section" of the Docker Remote API and the --tty option to docker run.

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#container_definition_pseudoterminal


readonlyRootFilesystemOptional
public readonly readonlyRootFilesystem: boolean;
  • Type: boolean
  • Default: false

When this parameter is true, the container is given read-only access to its root file system.


secretsOptional
public readonly secrets: {[ key: string ]: Secret};
  • Type: {[ key: string ]: aws-cdk-lib.aws_ecs.Secret}
  • Default: No secret environment variables.

The secret environment variables to pass to the container.


startTimeoutOptional
public readonly startTimeout: Duration;
  • Type: aws-cdk-lib.Duration
  • Default: none

Time duration (in seconds) to wait before giving up on resolving dependencies for a container.


stopTimeoutOptional
public readonly stopTimeout: Duration;
  • Type: aws-cdk-lib.Duration
  • Default: none

Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own.


systemControlsOptional
public readonly systemControls: SystemControl[];
  • Type: aws-cdk-lib.aws_ecs.SystemControl[]
  • Default: No system controls are set.

A list of namespaced kernel parameters to set in the container.

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#container_definition_systemcontrols


ulimitsOptional
public readonly ulimits: Ulimit[];
  • Type: aws-cdk-lib.aws_ecs.Ulimit[]

An array of ulimits to set in the container.


userOptional
public readonly user: string;
  • Type: string
  • Default: root

The user name to use inside the container.


workingDirectoryOptional
public readonly workingDirectory: string;
  • Type: string
  • Default: /

The working directory in which to run commands inside the container.


NextjsStandaloneEcsFargateServiceProps

ecs.FargateServiceProps Omit taskDefinition.

Initializer

import { NextjsStandaloneEcsFargateServiceProps } from 'cdk-nextjs-standalone-ecs'

const nextjsStandaloneEcsFargateServiceProps: NextjsStandaloneEcsFargateServiceProps = { ... }

Properties

Name Type Description
capacityProviderStrategies aws-cdk-lib.aws_ecs.CapacityProviderStrategy[] A list of Capacity Provider strategies used to place a service.
circuitBreaker aws-cdk-lib.aws_ecs.DeploymentCircuitBreaker Whether to enable the deployment circuit breaker.
cloudMapOptions aws-cdk-lib.aws_ecs.CloudMapOptions The options for configuring an Amazon ECS service to use service discovery.
deploymentController aws-cdk-lib.aws_ecs.DeploymentController Specifies which deployment controller to use for the service.
desiredCount number The desired number of instantiations of the task definition to keep running on the service.
enableECSManagedTags boolean Specifies whether to enable Amazon ECS managed tags for the tasks within the service.
enableExecuteCommand boolean Whether to enable the ability to execute into a container.
healthCheckGracePeriod aws-cdk-lib.Duration The period of time, in seconds, that the Amazon ECS service scheduler ignores unhealthy Elastic Load Balancing target health checks after a task has first started.
maxHealthyPercent number The maximum number of tasks, specified as a percentage of the Amazon ECS service's DesiredCount value, that can run in a service during a deployment.
minHealthyPercent number The minimum number of tasks, specified as a percentage of the Amazon ECS service's DesiredCount value, that must continue to run and remain healthy during a deployment.
propagateTags aws-cdk-lib.aws_ecs.PropagatedTagSource Specifies whether to propagate the tags from the task definition or the service to the tasks in the service.
serviceConnectConfiguration aws-cdk-lib.aws_ecs.ServiceConnectProps Configuration for Service Connect.
serviceName string The name of the service.
assignPublicIp boolean Specifies whether the task's elastic network interface receives a public IP address.
platformVersion aws-cdk-lib.aws_ecs.FargatePlatformVersion The platform version on which to run your service.
securityGroups aws-cdk-lib.aws_ec2.ISecurityGroup[] The security groups to associate with the service.
vpcSubnets aws-cdk-lib.aws_ec2.SubnetSelection The subnets to associate with the service.

capacityProviderStrategiesOptional
public readonly capacityProviderStrategies: CapacityProviderStrategy[];
  • Type: aws-cdk-lib.aws_ecs.CapacityProviderStrategy[]
  • Default: undefined

A list of Capacity Provider strategies used to place a service.


circuitBreakerOptional
public readonly circuitBreaker: DeploymentCircuitBreaker;
  • Type: aws-cdk-lib.aws_ecs.DeploymentCircuitBreaker
  • Default: disabled

Whether to enable the deployment circuit breaker.

If this property is defined, circuit breaker will be implicitly enabled.


cloudMapOptionsOptional
public readonly cloudMapOptions: CloudMapOptions;
  • Type: aws-cdk-lib.aws_ecs.CloudMapOptions
  • Default: AWS Cloud Map service discovery is not enabled.

The options for configuring an Amazon ECS service to use service discovery.


deploymentControllerOptional
public readonly deploymentController: DeploymentController;
  • Type: aws-cdk-lib.aws_ecs.DeploymentController
  • Default: Rolling update (ECS)

Specifies which deployment controller to use for the service.

For more information, see Amazon ECS Deployment Types


desiredCountOptional
public readonly desiredCount: number;
  • Type: number
  • Default: When creating the service, default is 1; when updating the service, default uses the current task number.

The desired number of instantiations of the task definition to keep running on the service.


enableECSManagedTagsOptional
public readonly enableECSManagedTags: boolean;
  • Type: boolean
  • Default: false

Specifies whether to enable Amazon ECS managed tags for the tasks within the service.

For more information, see Tagging Your Amazon ECS Resources


enableExecuteCommandOptional
public readonly enableExecuteCommand: boolean;
  • Type: boolean
  • Default: undefined

Whether to enable the ability to execute into a container.


healthCheckGracePeriodOptional
public readonly healthCheckGracePeriod: Duration;
  • Type: aws-cdk-lib.Duration
  • Default: defaults to 60 seconds if at least one load balancer is in-use and it is not already set

The period of time, in seconds, that the Amazon ECS service scheduler ignores unhealthy Elastic Load Balancing target health checks after a task has first started.


maxHealthyPercentOptional
public readonly maxHealthyPercent: number;
  • Type: number
  • Default: 100 if daemon, otherwise 200

The maximum number of tasks, specified as a percentage of the Amazon ECS service's DesiredCount value, that can run in a service during a deployment.


minHealthyPercentOptional
public readonly minHealthyPercent: number;
  • Type: number
  • Default: 0 if daemon, otherwise 50

The minimum number of tasks, specified as a percentage of the Amazon ECS service's DesiredCount value, that must continue to run and remain healthy during a deployment.


propagateTagsOptional
public readonly propagateTags: PropagatedTagSource;
  • Type: aws-cdk-lib.aws_ecs.PropagatedTagSource
  • Default: PropagatedTagSource.NONE

Specifies whether to propagate the tags from the task definition or the service to the tasks in the service.

Valid values are: PropagatedTagSource.SERVICE, PropagatedTagSource.TASK_DEFINITION or PropagatedTagSource.NONE


serviceConnectConfigurationOptional
public readonly serviceConnectConfiguration: ServiceConnectProps;
  • Type: aws-cdk-lib.aws_ecs.ServiceConnectProps
  • Default: No ports are advertised via Service Connect on this service, and the service cannot make requests to other services via Service Connect.

Configuration for Service Connect.


serviceNameOptional
public readonly serviceName: string;
  • Type: string
  • Default: CloudFormation-generated name.

The name of the service.


assignPublicIpOptional
public readonly assignPublicIp: boolean;
  • Type: boolean
  • Default: false

Specifies whether the task's elastic network interface receives a public IP address.

If true, each task will receive a public IP address.


platformVersionOptional
public readonly platformVersion: FargatePlatformVersion;
  • Type: aws-cdk-lib.aws_ecs.FargatePlatformVersion
  • Default: Latest

The platform version on which to run your service.

If one is not specified, the LATEST platform version is used by default. For more information, see AWS Fargate Platform Versions in the Amazon Elastic Container Service Developer Guide.


securityGroupsOptional
public readonly securityGroups: ISecurityGroup[];
  • Type: aws-cdk-lib.aws_ec2.ISecurityGroup[]
  • Default: A new security group is created.

The security groups to associate with the service.

If you do not specify a security group, a new security group is created.


vpcSubnetsOptional
public readonly vpcSubnets: SubnetSelection;
  • Type: aws-cdk-lib.aws_ec2.SubnetSelection
  • Default: Public subnets if assignPublicIp is set, otherwise the first available one of Private, Isolated, Public, in that order.

The subnets to associate with the service.


NextjsStandaloneEcsFileSystemProps

efs.FilesystemProps Omit vpc.

Initializer

import { NextjsStandaloneEcsFileSystemProps } from 'cdk-nextjs-standalone-ecs'

const nextjsStandaloneEcsFileSystemProps: NextjsStandaloneEcsFileSystemProps = { ... }

Properties

Name Type Description
enableAutomaticBackups boolean Whether to enable automatic backups for the file system.
encrypted boolean Defines if the data at rest in the file system is encrypted or not.
fileSystemName string The file system's name.
fileSystemPolicy aws-cdk-lib.aws_iam.PolicyDocument File system policy is an IAM resource policy used to control NFS access to an EFS file system.
kmsKey aws-cdk-lib.aws_kms.IKey The KMS key used for encryption.
lifecyclePolicy aws-cdk-lib.aws_efs.LifecyclePolicy A policy used by EFS lifecycle management to transition files to the Infrequent Access (IA) storage class.
outOfInfrequentAccessPolicy aws-cdk-lib.aws_efs.OutOfInfrequentAccessPolicy A policy used by EFS lifecycle management to transition files from Infrequent Access (IA) storage class to primary storage class.
performanceMode aws-cdk-lib.aws_efs.PerformanceMode The performance mode that the file system will operate under.
provisionedThroughputPerSecond aws-cdk-lib.Size Provisioned throughput for the file system.
removalPolicy aws-cdk-lib.RemovalPolicy The removal policy to apply to the file system.
securityGroup aws-cdk-lib.aws_ec2.ISecurityGroup Security Group to assign to this file system.
throughputMode aws-cdk-lib.aws_efs.ThroughputMode Enum to mention the throughput mode of the file system.
vpcSubnets aws-cdk-lib.aws_ec2.SubnetSelection Which subnets to place the mount target in the VPC.

enableAutomaticBackupsOptional
public readonly enableAutomaticBackups: boolean;
  • Type: boolean
  • Default: false

Whether to enable automatic backups for the file system.


encryptedOptional
public readonly encrypted: boolean;
  • Type: boolean
  • Default: If your application has the '@aws-cdk/aws-efs:defaultEncryptionAtRest' feature flag set, the default is true, otherwise, the default is false.

Defines if the data at rest in the file system is encrypted or not.

https://docs.aws.amazon.com/cdk/latest/guide/featureflags.html


fileSystemNameOptional
public readonly fileSystemName: string;
  • Type: string
  • Default: CDK generated name

The file system's name.


fileSystemPolicyOptional
public readonly fileSystemPolicy: PolicyDocument;
  • Type: aws-cdk-lib.aws_iam.PolicyDocument
  • Default: none

File system policy is an IAM resource policy used to control NFS access to an EFS file system.


kmsKeyOptional
public readonly kmsKey: IKey;
  • Type: aws-cdk-lib.aws_kms.IKey
  • Default: if 'encrypted' is true, the default key for EFS (/aws/elasticfilesystem) is used

The KMS key used for encryption.

This is required to encrypt the data at rest if @encrypted is set to true.


lifecyclePolicyOptional
public readonly lifecyclePolicy: LifecyclePolicy;
  • Type: aws-cdk-lib.aws_efs.LifecyclePolicy
  • Default: None. EFS will not transition files to the IA storage class.

A policy used by EFS lifecycle management to transition files to the Infrequent Access (IA) storage class.


outOfInfrequentAccessPolicyOptional
public readonly outOfInfrequentAccessPolicy: OutOfInfrequentAccessPolicy;
  • Type: aws-cdk-lib.aws_efs.OutOfInfrequentAccessPolicy
  • Default: None. EFS will not transition files from IA storage to primary storage.

A policy used by EFS lifecycle management to transition files from Infrequent Access (IA) storage class to primary storage class.


performanceModeOptional
public readonly performanceMode: PerformanceMode;
  • Type: aws-cdk-lib.aws_efs.PerformanceMode
  • Default: PerformanceMode.GENERAL_PURPOSE

The performance mode that the file system will operate under.

An Amazon EFS file system's performance mode can't be changed after the file system has been created. Updating this property will replace the file system.


provisionedThroughputPerSecondOptional
public readonly provisionedThroughputPerSecond: Size;
  • Type: aws-cdk-lib.Size
  • Default: none, errors out

Provisioned throughput for the file system.

This is a required property if the throughput mode is set to PROVISIONED. Must be at least 1MiB/s.


removalPolicyOptional
public readonly removalPolicy: RemovalPolicy;
  • Type: aws-cdk-lib.RemovalPolicy
  • Default: RemovalPolicy.RETAIN

The removal policy to apply to the file system.


securityGroupOptional
public readonly securityGroup: ISecurityGroup;
  • Type: aws-cdk-lib.aws_ec2.ISecurityGroup
  • Default: creates new security group which allows all outbound traffic

Security Group to assign to this file system.


throughputModeOptional
public readonly throughputMode: ThroughputMode;
  • Type: aws-cdk-lib.aws_efs.ThroughputMode
  • Default: ThroughputMode.BURSTING

Enum to mention the throughput mode of the file system.


vpcSubnetsOptional
public readonly vpcSubnets: SubnetSelection;
  • Type: aws-cdk-lib.aws_ec2.SubnetSelection
  • Default: the Vpc default strategy if not specified

Which subnets to place the mount target in the VPC.


NextjsStandaloneEcsSiteProps

Initializer

import { NextjsStandaloneEcsSiteProps } from 'cdk-nextjs-standalone-ecs'

const nextjsStandaloneEcsSiteProps: NextjsStandaloneEcsSiteProps = { ... }

Properties

Name Type Description
elbTargetGroup aws-cdk-lib.aws_elasticloadbalancingv2.IApplicationTargetGroup Must be on an ELB within the provided VPC.
vpc aws-cdk-lib.aws_ec2.IVpc No description.
clusterProps NextjsStandaloneEcsClusterProps Deviations from default settings: - "enableFargateCapacityProviders" is set to true.
containerProps NextjsStandaloneEcsContainerDefinitionOptions Complete deviation from default settings (as is required), but this is provided for overrides.
cpuArchitecture aws-cdk-lib.aws_ecs.CpuArchitecture Set your desired CPU architecture.
dockerImageAssetProps aws-cdk-lib.aws_ecr_assets.DockerImageAssetProps "platform" handled by this construct, do not recommend providing.
fileSystemAccessPointProps aws-cdk-lib.aws_efs.AccessPointOptions Complete deviation from default settings.
fileSystemPort number The port on which the file system is available.
fileSystemProps NextjsStandaloneEcsFileSystemProps Deviations from default settings: - "encrypted" is set to true.
gid string The POSIX group ID of the next.js docker user.
logStreamPrefix string The log stream prefix where the container's logs will be stored in Cloudwatch Logs.
nextjsContainerPort number The port on which the Next.js application is available inside the container.
serviceProps NextjsStandaloneEcsFargateServiceProps Deviations from default settings: - "assignPublicIp" is set to true, rather than false.
taskDefinitionProps aws-cdk-lib.aws_ecs.FargateTaskDefinitionProps "runtimePlatform" handled by this construct, do not recommend providing.
uid string The POSIX user ID of the next.js docker user.

elbTargetGroupRequired
public readonly elbTargetGroup: IApplicationTargetGroup;
  • Type: aws-cdk-lib.aws_elasticloadbalancingv2.IApplicationTargetGroup

Must be on an ELB within the provided VPC.


vpcRequired
public readonly vpc: IVpc;
  • Type: aws-cdk-lib.aws_ec2.IVpc

clusterPropsOptional
public readonly clusterProps: NextjsStandaloneEcsClusterProps;

Deviations from default settings: - "enableFargateCapacityProviders" is set to true.


containerPropsOptional
public readonly containerProps: NextjsStandaloneEcsContainerDefinitionOptions;

Complete deviation from default settings (as is required), but this is provided for overrides.

This will create an appropriate health check for the Next.js application, set sensible logging, the image, and the port.


cpuArchitectureOptional
public readonly cpuArchitecture: CpuArchitecture;
  • Type: aws-cdk-lib.aws_ecs.CpuArchitecture
  • Default: ecs.CpuArchitecture.X86_64

Set your desired CPU architecture.

Must be X86_64 if using FARGATE_SPOT, currently. To build ARM64 on an X86_64 machine, you must have emulators installed. You can use this command: docker run -it --rm --privileged tonistiigi/binfmt --install all


dockerImageAssetPropsOptional
public readonly dockerImageAssetProps: DockerImageAssetProps;
  • Type: aws-cdk-lib.aws_ecr_assets.DockerImageAssetProps

"platform" handled by this construct, do not recommend providing.

Docker Images must be created for every environment due to changing environment variables.

Deviations from default settings:

  • "directory" defaults to "./".
  • "platform" is handled by this construct to coincide with ECS.

fileSystemAccessPointPropsOptional
public readonly fileSystemAccessPointProps: AccessPointOptions;
  • Type: aws-cdk-lib.aws_efs.AccessPointOptions

Complete deviation from default settings.


fileSystemPortOptional
public readonly fileSystemPort: number;
  • Type: number
  • Default: 2049

The port on which the file system is available.


fileSystemPropsOptional
public readonly fileSystemProps: NextjsStandaloneEcsFileSystemProps;

Deviations from default settings: - "encrypted" is set to true.

"lifecyclePolicy" is set to "AFTER_90_DAYS" in order to transition old builds to the IA class.

  • "removalPolicy" is set to DESTROY.

gidOptional
public readonly gid: string;
  • Type: string
  • Default: "1001"

The POSIX group ID of the next.js docker user.


logStreamPrefixOptional
public readonly logStreamPrefix: string;
  • Type: string
  • Default: "nextjs-standalone-ecs-site"

The log stream prefix where the container's logs will be stored in Cloudwatch Logs.


nextjsContainerPortOptional
public readonly nextjsContainerPort: number;
  • Type: number
  • Default: 3000

The port on which the Next.js application is available inside the container.


servicePropsOptional
public readonly serviceProps: NextjsStandaloneEcsFargateServiceProps;

Deviations from default settings: - "assignPublicIp" is set to true, rather than false.

This is done because most Next.js applications are public. If you would rather use a NatGateway, you can override this prop.


taskDefinitionPropsOptional
public readonly taskDefinitionProps: FargateTaskDefinitionProps;
  • Type: aws-cdk-lib.aws_ecs.FargateTaskDefinitionProps

"runtimePlatform" handled by this construct, do not recommend providing.

No other deviations from default settings.


uidOptional
public readonly uid: string;
  • Type: string
  • Default: "1001"

The POSIX user ID of the next.js docker user.