-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fargate CDK Stack Does Not Build Properly and Will Not Deploy Under Amplify #12972
Comments
Hey @maxschnupp 👋 thanks for raising this! Are you seeing this issue particularly with the L3 construct shown in your snippet? Also please note there is a limitation with custom CDK resources where you are unable to point the image build to a local asset, meaning you are unable to use |
Hi @josefaidt thanks for getting on this so quickly, Yes we are seeing this issue with the L3 construct as in the snippet, we tried to workaround this by composing multiple constructs together to get the same functionality but we still got the same error We realised that in the We are not using |
Hey @maxschnupp thanks for clarifying! I'm able to reproduce this with the sample custom resource: 🛑 The following resources failed to deploy:
Resource Name: MyWebServerService2FE7341D (AWS::ECS::Service)
Event Type: create
Reason: Resource handler returned message: "Invalid request provided: CreateService error: The target group with targetGroupArn arn:aws:elasticloadbalancing:us-east-1:814763596509:targetgroup/amplif-MyWeb-AVHXZIKH8MQ2/e8c1a2e59159aa89 does not have an associated load balancer. (Service: AmazonECS; Status Code: 400; Error Code: InvalidParameterException; Request ID: a6d45eef-4347-4ad2-9e2d-a5e73d46ecc4; Proxy: null)" (RequestToken: a2afa4fc-c933-40a6-4943-63d18a84673a, HandlerErrorCode: InvalidRequest)
🛑 CFN Deployment failed for custom resources.
Name: MyWebServerService2FE7341D (AWS::ECS::Service), Event Type: create, Reason: Resource handler returned message: "Invalid request provided: CreateService error: The target group with targetGroupArn arn:aws:elasticloadbalancing:us-east-1:814763596509:targetgroup/amplif-MyWeb-AVHXZIKH8MQ2/e8c1a2e59159aa89 does not have an associated load balancer. (Service: AmazonECS; Status Code: 400; Error Code: InvalidParameterException; Request ID: a6d45eef-4347-4ad2-9e2d-a5e73d46ecc4; Proxy: null)" (RequestToken: a2afa4fc-c933-40a6-4943-63d18a84673a, HandlerErrorCode: InvalidRequest), IsCustomResource: true Which is a bit strange because I also see a load balancer get cleaned up after the resource in error failed
CFN template{
"Parameters": {
"env": {
"Type": "String",
"Description": "Current Amplify CLI env name"
}
},
"Resources": {
"MyWebServerLB3B5FD3AB": {
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
"Properties": {
"LoadBalancerAttributes": [
{
"Key": "deletion_protection.enabled",
"Value": "false"
}
],
"Scheme": "internet-facing",
"SecurityGroups": [
{
"Fn::GetAtt": [
"MyWebServerLBSecurityGroup01B285AA",
"GroupId"
]
}
],
"Subnets": [
{
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPublicSubnet1Subnet3C273B99"
},
{
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPublicSubnet2Subnet95FF715A"
}
],
"Type": "application"
}
},
"MyWebServerLBSecurityGroup01B285AA": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Automatically created Security Group for ELB MyWebServerLB003C2F84",
"SecurityGroupIngress": [
{
"CidrIp": "0.0.0.0/0",
"Description": "Allow from anyone on port 80",
"FromPort": 80,
"IpProtocol": "tcp",
"ToPort": 80
}
],
"VpcId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpc7788A521"
}
}
},
"MyWebServerLBSecurityGrouptoMyWebServerServiceSecurityGroup408CA18A80531B81C6": {
"Type": "AWS::EC2::SecurityGroupEgress",
"Properties": {
"GroupId": {
"Fn::GetAtt": [
"MyWebServerLBSecurityGroup01B285AA",
"GroupId"
]
},
"IpProtocol": "tcp",
"Description": "Load balancer to target",
"DestinationSecurityGroupId": {
"Fn::GetAtt": [
"MyWebServerServiceSecurityGroup6788214A",
"GroupId"
]
},
"FromPort": 80,
"ToPort": 80
}
},
"MyWebServerLBPublicListener03D7C493": {
"Type": "AWS::ElasticLoadBalancingV2::Listener",
"Properties": {
"DefaultActions": [
{
"TargetGroupArn": {
"Ref": "MyWebServerLBPublicListenerECSGroup5AB9F1C3"
},
"Type": "forward"
}
],
"LoadBalancerArn": {
"Ref": "MyWebServerLB3B5FD3AB"
},
"Port": 80,
"Protocol": "HTTP"
}
},
"MyWebServerLBPublicListenerECSGroup5AB9F1C3": {
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
"Properties": {
"Port": 80,
"Protocol": "HTTP",
"TargetGroupAttributes": [
{
"Key": "stickiness.enabled",
"Value": "false"
}
],
"TargetType": "ip",
"VpcId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpc7788A521"
}
}
},
"MyWebServerTaskDefTaskRoleB23C17AA": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
}
}
],
"Version": "2012-10-17"
}
}
},
"MyWebServerTaskDef4CE825A0": {
"Type": "AWS::ECS::TaskDefinition",
"Properties": {
"ContainerDefinitions": [
{
"Essential": true,
"Image": "amazon/amazon-ecs-sample",
"LogConfiguration": {
"LogDriver": "awslogs",
"Options": {
"awslogs-group": {
"Ref": "MyWebServerTaskDefwebLogGroupC6EE23D4"
},
"awslogs-stream-prefix": "MyWebServer",
"awslogs-region": {
"Ref": "AWS::Region"
}
}
},
"Name": "web",
"PortMappings": [
{
"ContainerPort": 80,
"Protocol": "tcp"
}
]
}
],
"Cpu": "256",
"ExecutionRoleArn": {
"Fn::GetAtt": [
"MyWebServerTaskDefExecutionRole3C69E361",
"Arn"
]
},
"Family": "MyWebServerTaskDef7B3B7949",
"Memory": "512",
"NetworkMode": "awsvpc",
"RequiresCompatibilities": [
"FARGATE"
],
"TaskRoleArn": {
"Fn::GetAtt": [
"MyWebServerTaskDefTaskRoleB23C17AA",
"Arn"
]
}
}
},
"MyWebServerTaskDefwebLogGroupC6EE23D4": {
"Type": "AWS::Logs::LogGroup",
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"MyWebServerTaskDefExecutionRole3C69E361": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
}
}
],
"Version": "2012-10-17"
}
}
},
"MyWebServerTaskDefExecutionRoleDefaultPolicy2AEB4329": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Effect": "Allow",
"Resource": {
"Fn::GetAtt": [
"MyWebServerTaskDefwebLogGroupC6EE23D4",
"Arn"
]
}
}
],
"Version": "2012-10-17"
},
"PolicyName": "MyWebServerTaskDefExecutionRoleDefaultPolicy2AEB4329",
"Roles": [
{
"Ref": "MyWebServerTaskDefExecutionRole3C69E361"
}
]
}
},
"MyWebServerService2FE7341D": {
"Type": "AWS::ECS::Service",
"Properties": {
"Cluster": {
"Ref": "EcsDefaultClusterMnL3mNNYN926A5246"
},
"DeploymentConfiguration": {
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"EnableECSManagedTags": false,
"HealthCheckGracePeriodSeconds": 60,
"LaunchType": "FARGATE",
"LoadBalancers": [
{
"ContainerName": "web",
"ContainerPort": 80,
"TargetGroupArn": {
"Ref": "MyWebServerLBPublicListenerECSGroup5AB9F1C3"
}
}
],
"NetworkConfiguration": {
"AwsvpcConfiguration": {
"AssignPublicIp": "DISABLED",
"SecurityGroups": [
{
"Fn::GetAtt": [
"MyWebServerServiceSecurityGroup6788214A",
"GroupId"
]
}
],
"Subnets": [
{
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet1Subnet075EFF4C"
},
{
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet2SubnetE4CEDF73"
}
]
}
},
"TaskDefinition": {
"Ref": "MyWebServerTaskDef4CE825A0"
}
}
},
"MyWebServerServiceSecurityGroup6788214A": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Default/MyWebServer/Service/SecurityGroup",
"SecurityGroupEgress": [
{
"CidrIp": "0.0.0.0/0",
"Description": "Allow all outbound traffic by default",
"IpProtocol": "-1"
}
],
"VpcId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpc7788A521"
}
}
},
"MyWebServerServiceSecurityGroupfromMyWebServerLBSecurityGroup768CB24C80FFD8DBEB": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
"IpProtocol": "tcp",
"Description": "Load balancer to target",
"FromPort": 80,
"GroupId": {
"Fn::GetAtt": [
"MyWebServerServiceSecurityGroup6788214A",
"GroupId"
]
},
"SourceSecurityGroupId": {
"Fn::GetAtt": [
"MyWebServerLBSecurityGroup01B285AA",
"GroupId"
]
},
"ToPort": 80
}
},
"EcsDefaultClusterMnL3mNNYN926A5246": {
"Type": "AWS::ECS::Cluster"
},
"EcsDefaultClusterMnL3mNNYNVpc7788A521": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16",
"EnableDnsHostnames": true,
"EnableDnsSupport": true,
"InstanceTenancy": "default"
}
},
"EcsDefaultClusterMnL3mNNYNVpcPublicSubnet1Subnet3C273B99": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpc7788A521"
},
"AvailabilityZone": {
"Fn::Select": [
0,
{
"Fn::GetAZs": ""
}
]
},
"CidrBlock": "10.0.0.0/18",
"MapPublicIpOnLaunch": true
}
},
"EcsDefaultClusterMnL3mNNYNVpcPublicSubnet1RouteTableA1FD6ACC": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpc7788A521"
}
}
},
"EcsDefaultClusterMnL3mNNYNVpcPublicSubnet1RouteTableAssociation8B583A17": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPublicSubnet1RouteTableA1FD6ACC"
},
"SubnetId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPublicSubnet1Subnet3C273B99"
}
}
},
"EcsDefaultClusterMnL3mNNYNVpcPublicSubnet1DefaultRouteFF4E2178": {
"Type": "AWS::EC2::Route",
"Properties": {
"RouteTableId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPublicSubnet1RouteTableA1FD6ACC"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcIGW9C2C2B8F"
}
}
},
"EcsDefaultClusterMnL3mNNYNVpcPublicSubnet1EIP8704DB2F": {
"Type": "AWS::EC2::EIP",
"Properties": {
"Domain": "vpc"
}
},
"EcsDefaultClusterMnL3mNNYNVpcPublicSubnet1NATGateway5E3732C1": {
"Type": "AWS::EC2::NatGateway",
"Properties": {
"SubnetId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPublicSubnet1Subnet3C273B99"
},
"AllocationId": {
"Fn::GetAtt": [
"EcsDefaultClusterMnL3mNNYNVpcPublicSubnet1EIP8704DB2F",
"AllocationId"
]
}
}
},
"EcsDefaultClusterMnL3mNNYNVpcPublicSubnet2Subnet95FF715A": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpc7788A521"
},
"AvailabilityZone": {
"Fn::Select": [
1,
{
"Fn::GetAZs": ""
}
]
},
"CidrBlock": "10.0.64.0/18",
"MapPublicIpOnLaunch": true
}
},
"EcsDefaultClusterMnL3mNNYNVpcPublicSubnet2RouteTable263DEAA5": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpc7788A521"
}
}
},
"EcsDefaultClusterMnL3mNNYNVpcPublicSubnet2RouteTableAssociation43E5803C": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPublicSubnet2RouteTable263DEAA5"
},
"SubnetId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPublicSubnet2Subnet95FF715A"
}
}
},
"EcsDefaultClusterMnL3mNNYNVpcPublicSubnet2DefaultRouteB1375520": {
"Type": "AWS::EC2::Route",
"Properties": {
"RouteTableId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPublicSubnet2RouteTable263DEAA5"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcIGW9C2C2B8F"
}
}
},
"EcsDefaultClusterMnL3mNNYNVpcPublicSubnet2EIPF0764873": {
"Type": "AWS::EC2::EIP",
"Properties": {
"Domain": "vpc"
}
},
"EcsDefaultClusterMnL3mNNYNVpcPublicSubnet2NATGateway4C855E00": {
"Type": "AWS::EC2::NatGateway",
"Properties": {
"SubnetId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPublicSubnet2Subnet95FF715A"
},
"AllocationId": {
"Fn::GetAtt": [
"EcsDefaultClusterMnL3mNNYNVpcPublicSubnet2EIPF0764873",
"AllocationId"
]
}
}
},
"EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet1Subnet075EFF4C": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpc7788A521"
},
"AvailabilityZone": {
"Fn::Select": [
0,
{
"Fn::GetAZs": ""
}
]
},
"CidrBlock": "10.0.128.0/18",
"MapPublicIpOnLaunch": false
}
},
"EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet1RouteTable4F1D2E36": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpc7788A521"
}
}
},
"EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet1RouteTableAssociation34B92275": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet1RouteTable4F1D2E36"
},
"SubnetId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet1Subnet075EFF4C"
}
}
},
"EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet1DefaultRouteA5ADF694": {
"Type": "AWS::EC2::Route",
"Properties": {
"RouteTableId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet1RouteTable4F1D2E36"
},
"DestinationCidrBlock": "0.0.0.0/0",
"NatGatewayId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPublicSubnet1NATGateway5E3732C1"
}
}
},
"EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet2SubnetE4CEDF73": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpc7788A521"
},
"AvailabilityZone": {
"Fn::Select": [
1,
{
"Fn::GetAZs": ""
}
]
},
"CidrBlock": "10.0.192.0/18",
"MapPublicIpOnLaunch": false
}
},
"EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet2RouteTableDCE46591": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpc7788A521"
}
}
},
"EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet2RouteTableAssociation111C622F": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet2RouteTableDCE46591"
},
"SubnetId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet2SubnetE4CEDF73"
}
}
},
"EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet2DefaultRoute20CE2D89": {
"Type": "AWS::EC2::Route",
"Properties": {
"RouteTableId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPrivateSubnet2RouteTableDCE46591"
},
"DestinationCidrBlock": "0.0.0.0/0",
"NatGatewayId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcPublicSubnet2NATGateway4C855E00"
}
}
},
"EcsDefaultClusterMnL3mNNYNVpcIGW9C2C2B8F": {
"Type": "AWS::EC2::InternetGateway"
},
"EcsDefaultClusterMnL3mNNYNVpcVPCGW2447264E": {
"Type": "AWS::EC2::VPCGatewayAttachment",
"Properties": {
"VpcId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpc7788A521"
},
"InternetGatewayId": {
"Ref": "EcsDefaultClusterMnL3mNNYNVpcIGW9C2C2B8F"
}
}
}
},
"Outputs": {
"MyWebServerLoadBalancerDNSD1AFCC81": {
"Value": {
"Fn::GetAtt": [
"MyWebServerLB3B5FD3AB",
"DNSName"
]
}
},
"MyWebServerServiceURLB0ED50F6": {
"Value": {
"Fn::Join": [
"",
[
"http://",
{
"Fn::GetAtt": [
"MyWebServerLB3B5FD3AB",
"DNSName"
]
}
]
]
}
}
},
"Description": "{\"createdOn\":\"Mac\",\"createdBy\":\"Amplify\",\"createdWith\":\"12.2.0-rc.a3b139fb36.0\",\"stackType\":\"custom-customCDK\",\"metadata\":{}}"
} As you noted, I do not see any |
Hey @maxschnupp after further review this is found to be a bug in the way Amplify CLI is synthesizing CloudFormation templates for custom resources. I'll mark this issue accordingly |
Upon further review I will close this as a duplicate report of #12702 |
|
How did you install the Amplify CLI?
via npm
If applicable, what version of Node.js are you using?
20.2.0
Amplify CLI Version
12.1.1
What operating system are you using?
Mac
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No, we only make changes through the CLI
Describe the bug
We are having a little difficulty integrating fargate into our amplify application.
We are able to create a fargate service using cdk in a new cdk project as per this quick-start guide
We are trying to add a Fargate service to our amplify backend using a custom cdk stack
When we try to build essentially the same code within a custom cdk stack in our amplify application, we note that the
cloudformation-template.json
file produced is missing theDependsOn
properties we would expect to see set for the individual components of the serviceWhen we try to deploy with
amplify push
deployment fails due to an ordering issue in which the target group deployment starts before the load balancer is readyWe get the following error message:
Expected behavior
Deploys with amplify like the version with CDK CLI and we are able to access the sample PHP application over the world wide web
Reproduction steps
amplify init -y
amplify add custom
fargate-service/cdk-stack.ts
now looks like this:amplify build custom fargateService
build/fargateService-cloudformation-template.json
does not contain any of the ‘DependsOn’ fields that you would have after this step if you followed the CDK quick-start in a CDK projectamplify push -y
Project Identifier
No response
Log output
Additional information
No response
Before submitting, please confirm:
The text was updated successfully, but these errors were encountered: