from aws_cdk import (aws_autoscaling as autoscaling, aws_ec2 as ec2, aws_ecs as ecs, App, Stack) # Based on https://aws.amazon.com/blogs/compute/introducing-cloud-native-networking-for-ecs-containers/ app = App() stack = Stack(app, "ec2-service-with-task-networking") # Create a cluster vpc = ec2.Vpc(stack, "Vpc", max_azs=2) cluster = ecs.Cluster(stack, "awsvpc-ecs-demo-cluster", vpc=vpc) asg = autoscaling.AutoScalingGroup( stack, "DefaultAutoScalingGroup", instance_type=ec2.InstanceType("t2.micro"), machine_image=ecs.EcsOptimizedImage.amazon_linux2(), vpc=vpc, ) capacity_provider = ecs.AsgCapacityProvider(stack, "AsgCapacityProvider", auto_scaling_group=asg) cluster.add_asg_capacity_provider(capacity_provider) # Create a task definition with its own elastic network interface task_definition = ecs.Ec2TaskDefinition( stack, "nginx-awsvpc", network_mode=ecs.NetworkMode.AWS_VPC, )
from aws_cdk import (aws_autoscaling as autoscaling, aws_ec2 as ec2, aws_ecs as ecs, App, Stack) app = App() stack = Stack(app, "aws-ecs-integ-ecs") # Create a cluster vpc = ec2.Vpc(stack, "Vpc", max_azs=2) cluster = ecs.Cluster(stack, "EcsCluster", vpc=vpc) asg = autoscaling.AutoScalingGroup( stack, "DefaultAutoScalingGroup", instance_type=ec2.InstanceType("t2.micro"), machine_image=ecs.EcsOptimizedImage.amazon_linux2(), vpc=vpc, ) capacity_provider = ecs.AsgCapacityProvider(stack, "AsgCapacityProvider", auto_scaling_group=asg) cluster.add_asg_capacity_provider(capacity_provider) # Create a task definition with placement constraints task_definition = ecs.Ec2TaskDefinition( stack, "TaskDef", placement_constraints=[ecs.PlacementConstraint.distinct_instances()]) container = task_definition.add_container( "web",
from constructs import Construct from aws_cdk import ( Duration, Stack, aws_iam as iam, aws_sqs as sqs, aws_sns as sns, aws_sns_subscriptions as subs, ) class %name.PascalCased%Stack(core.Stack): def __init__(self, scope: core.Construct, construct_id: str, **kwargs) -> None: super().__init__(scope, construct_id, **kwargs) queue = sqs.Queue( self, "%name.PascalCased%Queue", visibility_timeout=core.Duration.seconds(300), ) topic = sns.Topic( self, "%name.PascalCased%Topic" ) topic.add_subscription(subs.SqsSubscription(queue))
from constructs import Construct from aws_cdk import ( Duration, Stack, aws_iam as iam, aws_sqs as sqs, aws_sns as sns, aws_sns_subscriptions as subs, ) class %name.PascalCased%Stack(Stack): def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: super().__init__(scope, construct_id, **kwargs) queue = sqs.Queue( self, "%name.PascalCased%Queue", visibility_timeout=Duration.seconds(300), ) topic = sns.Topic( self, "%name.PascalCased%Topic" ) topic.add_subscription(subs.SqsSubscription(queue))