You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
I'm trying to deploy a side project cheaply and found this post by Aidan Steele on his blog called Cheap serverless containers using API Gateway in which he outlines how to deploy an ECS service/task without using an ALB, which are pricy. He provides 2 complete Cloudformation templates which I'm trying to convert into CDK. Here is what I have so far
fromaws_cdkimportStackfromaws_cdkimportaws_apigatewayv2asapigatewayv2fromaws_cdkimportaws_certificatemanagerasacmfromaws_cdkimportaws_ec2asec2fromaws_cdkimportaws_route53asroute53fromaws_cdkimportaws_servicediscoveryasservicediscoveryfromconstructsimportConstructfromstacksimportHOSTED_ZONE_ID, VPC_ID, DOMAIN_NAMEclassMetaCheapInfraStack(Stack):
def__init__(self, scope: Construct, id: str, **kwargs) ->None:
super().__init__(scope, id, **kwargs)
# Create a VPCself.vpc=ec2.Vpc.from_lookup(self, "VPC", vpc_id=VPC_ID)
# Create subnetsself.subnet_a=ec2.Subnet(
self,
"SubnetA",
vpc_id=self.vpc.vpc_id,
cidr_block="10.1.1.0/24",
availability_zone=f"{self.region}a",
)
self.subnet_b=ec2.Subnet(
self,
"SubnetB",
vpc_id=self.vpc.vpc_id,
cidr_block="10.1.2.0/24",
availability_zone=f"{self.region}b",
)
# Create a Route 53 hosted zoneself.hosted_zone=route53.HostedZone.from_hosted_zone_attributes(
self,
"HostedZone",
hosted_zone_id=HOSTED_ZONE_ID,
zone_name=DOMAIN_NAME,
)
# Create an ACM-managed TLS certificateself.certificate=acm.Certificate(
self,
"Certificate",
domain_name="dev."+DOMAIN_NAME,
validation=acm.CertificateValidation.from_dns(hosted_zone=self.hosted_zone),
)
# Create a security group for the VPC linkself.vpc_link_security_group=ec2.SecurityGroup(
self,
"VpcLinkSecurityGroup",
vpc=self.vpc,
description="VPC link security group",
)
# Create an API Gateway VPC Linkself.vpc_link=apigatewayv2.VpcLink(
self,
"VpcLink",
vpc=self.vpc,
security_groups=[self.vpc_link_security_group],
subnets=ec2.SubnetSelection(subnets=[self.subnet_a, self.subnet_b]),
)
# Create a Cloud Map namespaceself.cloud_map_namespace=servicediscovery.PrivateDnsNamespace(
self, "CloudMapNamespace", vpc=self.vpc, name=DOMAIN_NAME
)
# Create a route tableself.route_table=ec2.CfnRouteTable(self, "RouteTable", vpc_id=self.vpc.vpc_id)
# Create a routeec2.CfnRoute(
self,
"InternetRoute",
route_table_id=self.route_table.attr_route_table_id,
destination_cidr_block="0.0.0.0/0",
gateway_id=ec2.CfnInternetGateway(self, "InternetGateway"),
)
# Associate the subnets with the route tableec2.SubnetRouteTableAssociation(
self,
"RouteTableAssociationSubnetA",
subnet_id=self.subnet_a,
route_table_id=self.route_table.attr_route_table_id,
)
ec2.SubnetRouteTableAssociation(
self,
"RouteTableAssociationSubnetB",
subnet_id=self.subnet_b,
route_table_id=self.route_table.attr_route_table_id,
)
But i get unsure of myself when we get into the ec2.CfnRouteTable and Cfn* in general as this is sort of stuff I usually rely on CDK for (and permissions). This is failing because the CfnRoute wants a gateway_id not an actual CfnInternetGateway... but I get the feeling I should be using something from aws_apigatewayv2 here?
Anyway, if anyone has some tips as to how to make this more high level, its be much appreciated,
Thanks!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi!
I'm trying to deploy a side project cheaply and found this post by Aidan Steele on his blog called Cheap serverless containers using API Gateway in which he outlines how to deploy an ECS service/task without using an ALB, which are pricy. He provides 2 complete Cloudformation templates which I'm trying to convert into CDK. Here is what I have so far
But i get unsure of myself when we get into the
ec2.CfnRouteTable
andCfn*
in general as this is sort of stuff I usually rely on CDK for (and permissions). This is failing because theCfnRoute
wants agateway_id
not an actualCfnInternetGateway
... but I get the feeling I should be using something fromaws_apigatewayv2
here?Anyway, if anyone has some tips as to how to make this more high level, its be much appreciated,
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions