-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
aws_route53: cannot use CfnParameter.valueAsNumber for L2 RecordSet weight #31810
Comments
@nicholaschiasson Good afternoon. Thanks for opening the issue. Issue is reproducible using below code: import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as r53 from 'aws-cdk-lib/aws-route53';
import * as r53targets from 'aws-cdk-lib/aws-route53-targets';
import { ApplicationLoadBalancer } from 'aws-cdk-lib/aws-elasticloadbalancingv2';
export class CdktestStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const domainName = 'example.com';
const vpc = ec2.Vpc.fromLookup(this, 'DefaultVpc', { isDefault: true });
const weightParameter = new cdk.CfnParameter(this, 'Weight', {
default: 0,
maxValue: 255,
minValue: 0,
type: 'Number'
});
const zone = r53.HostedZone.fromLookup(this, 'HostedZone', {
domainName: 'example.com'
});
const loadBalancer = new ApplicationLoadBalancer(this, 'ServiceLB', {
vpc,
internetFacing: true
});
const serviceSG = new ec2.SecurityGroup(this, 'ServiceSecurityGroup', { vpc });
serviceSG.connections.allowFrom(loadBalancer, ec2.Port.tcp(80));
console.log(`${weightParameter}`);
const aRecord = new r53.ARecord(this, 'ARecord', {
target: r53.RecordTarget.fromAlias(new r53targets.LoadBalancerTarget(loadBalancer)),
weight: weightParameter.valueAsNumber,
zone
});
}
} However, although AWS CloudFormation parameters can be defined in the AWS CDK, they are generally discouraged because AWS CloudFormation parameters are resolved only during deployment. This means that you cannot determine their value in your code. Because the AWS CDK takes an approach where concrete templates are resolved at synthesis time and so is the validation in this case, the alternative approach is to use context values either from the command line or via the cdk.json. Refer Parameters and the AWS CDK for details. So in your use case, you could modify your code as below:
and run Thanks, |
Hi @ashishdhingra , thanks for your quick response. I'm aware of parameters being discouraged in favour of context arguments. Still, I consider this an unexpected behaviour and for my use case, I strongly prefer the use of a CFN parameter for this. Here are some similar issues I was able to find which have been stated this behaviour is a bug, and which have been resolved: #7126 #9038 I imagine the fix should be similar to the fixes for those issues as well: #8252 #9176 Indeed, in the current HEAD on main branch, I see the I will try to open a PR to resolve this since it looks to be a simple fix. |
@nicholaschiasson I've implemented this validation and this is my fault for not checking whether |
@nicholaschiasson Thanks for pointing to related issues and PR contribution. |
Comments on closed issues and PRs are hard for our team to see. |
1 similar comment
Comments on closed issues and PRs are hard for our team to see. |
Describe the bug
Cannot construct
ARecord
(and presumably anyRecordSet
) withweight
resolved byCfnParameter
value.Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
RecordSet
should successfully be synthesized with the parameter's token value for the weight.Current Behavior
Synthesis fails, token value representing a number outside the bounds of a valid weight (0-255).
Reproduction Steps
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.151.0 (build b8289e2)
Framework Version
No response
Node.js Version
v20.13.1
OS
Linux 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 x86_64 GNU/Linux
Language
TypeScript
Language Version
No response
Other information
Currently using this workaround:
The text was updated successfully, but these errors were encountered: