Home > Software design >  How can i resolve token in general?
How can i resolve token in general?

Time:07-28

Can you help me please? I have a parameter

env_name = CfnParameter(self, "EnvName", type="String", description="Name of environment", default="")

and code

my_env_name = env_name.value.to_string() ""
self.vpc = ec2.Vpc(self, "VPC",
           vpc_name=my_env_name "-vpc",
           subnet_configuration=[ec2.SubnetConfiguration(
               subnet_type=ec2.SubnetType.PUBLIC,
               name=my_env_name "-public",
               cidr_mask=21
           )

When i do vpc_name=my_env_name "-vpc" - all good, VPC is creating with required name.

When i try to do name=my_env_name "-public" i have error message ID components may not include unresolved tokens: ${Token[EnvName.Ref.212]}-publicSubnet1.

When i try to do name=Token.as_string(Fn.ref("EnvName")) - error message Resolution error: ID components may not include unresolved tokens: ${Token[TOKEN.218]}Subnet1.

How can i resolve token in general?

CodePudding user response:

To expand on @gshpychka's comment, tokens represent values that are not known at synthesis time. You can read more about them here: https://docs.aws.amazon.com/cdk/v2/guide/tokens.html

Tokens cannot be resolved during synthesis, so in your case vpc_name=my_env_name "-vpc" works because the CDK will turn that into a Cfn intrinsic functions that will resolve the value during the deployment of the stack.

  • Related