I am creating an ALB via Cloudformation Template. One of the resources being created is a target group that will use EC2 instance ID’s that were exported during a previous job. I need to import the values and sub the import name to reflect different environment deployments. Running the cfn-lint tool, this is a correct template:
AWSTemplateFormatVersion: "2010-09-09"
Description: Creates an application load balancer.
Parameters:
pSystem:
Type: String
Default: your-system-name
Description: 'Name of the system. Default: your-system-name'
pApp:
Type: String
Description: 'Name of the application solution'
pEnvironment:
Type: String
Default: sbx
Description: 'Name of the deployment tier. Default: sbx'
pVpcId:
Type: AWS::SSM::Parameter::Value<String>
Resources:
rLoadBalancerTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Name: !Sub '${pSystem}-${pApp}-${pEnvironment}-public-tg'
HealthCheckEnabled: true
HealthCheckIntervalSeconds: 60
HealthCheckPath: 'REDACTED'
HealthCheckPort: 1234
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 10
HealthyThresholdCount: 2
Matcher:
HttpCode: 200-299
Port: 1234
Protocol: HTTP
ProtocolVersion: HTTP1
TargetGroupAttributes:
- Key: 'deregistration_delay.timeout_seconds'
Value: 300
- Key: 'stickiness.enabled'
Value: false
- Key: 'load_balancing.algorithm.type'
Value: round_robin
- Key: 'slow_start.duration_seconds'
Value: 0
TargetType: instance
UnhealthyThresholdCount: 2
VpcId: !Ref pVpcId
Targets:
- Id: !ImportValue
Fn::Sub: '${pSystem}-${pApp}-01-${pEnvironment}-ec2-id'
- Id: !ImportValue
Fn::Sub: "${pSystem}-${pApp}-02-${pEnvironment}-ec2-id"
- Id: !ImportValue
Fn::Sub: "${pSystem}-${pApp}-03-${pEnvironment}-ec2-id"
However, I receive this error in Cloudformation when it attempts to deploy:
No export named found
Which I have verified that all of my expected exports match this naming convention and are present in their respective stacks.
Reviewing the Template in Cloudformation, the template is translated to:
AWSTemplateFormatVersion: "2010-09-09"
Description: Creates an application load balancer.
Parameters:
pSystem:
Type: String
Default: your-system-name
Description: 'Name of the system. Default: your-system-name'
pApp:
Type: String
Description: 'Name of the application solution'
pEnvironment:
Type: String
Default: sbx
Description: 'Name of the deployment tier. Default: sbx'
pVpcId:
Type: AWS::SSM::Parameter::Value<String>
Resources:
rLoadBalancerTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Name:
Fn::Sub: ${pSystem}-${pApp}-${pEnvironment}-public-tg
HealthCheckEnabled: true
HealthCheckIntervalSeconds: 60
HealthCheckPath: /rest/web/system-healthy
HealthCheckPort: 30600
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 10
HealthyThresholdCount: 2
Matcher:
HttpCode: 200-299
Port: 30600
Protocol: HTTP
ProtocolVersion: HTTP1
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: 300
- Key: stickiness.enabled
Value: false
- Key: load_balancing.algorithm.type
Value: round_robin
- Key: slow_start.duration_seconds
Value: 0
TargetType: instance
UnhealthyThresholdCount: 2
VpcId:
Ref: pVpcId
Targets:
- Id:
Fn::ImportValue: ''
Fn::Sub: ${pSystem}-${pApp}-01-${pEnvironment}-ec2-id
- Id:
Fn::ImportValue: ''
Fn::Sub: ${pSystem}-${pApp}-02-${pEnvironment}-ec2-id
- Id:
Fn::ImportValue: ''
Fn::Sub: ${pSystem}-${pApp}-03-${pEnvironment}-ec2-id
Which has an empty string (”) after the Fn::ImportValue, and doesn’t appear to be reading the Sub command.
Any suggestions on how to import the EC2 instance ID’s for the target group?