Robin Nicole
Robin Nicole

Reputation: 113

Equivalent of !Ref in aws cdk

I am currently using aws-cdk to generate a cloudformation template and I would like to access a parameters defined with

CfnParameter(self, id="Platform", type="String", default="My Platform")

with a reference (Like !Ref Platform in a cloudformation template)

Any of you know what is the equivalent of a Ref in the aws cdk.

Here is the yaml equivalent of the parameter I defined above

Parameters:
  Platform:
    Type: String
    Default: "My Platform"

Upvotes: 3

Views: 4289

Answers (2)

HFR1994
HFR1994

Reputation: 576

Old question, but for someone still looking for an answer you can do:

const plataform = new CfnParameter(this, "Platform", {
   type: "String",
   default: "MyPlataform"
});

const deploymentRole = new Role(this, 'DeploymentRole', {
    assumedBy: new ArnPrincipal("Some ARN"),
    roleName: Fn.join("-",[plataform.valueAsString,"role"])
});

Upvotes: 1

Vikyol
Vikyol

Reputation: 5645

It depends on which construct you are using.

For low-level constructs, so called CFN resources, you can use the ref property. For high-level constructs, you should check the API for xxx_id property. In the example below, the cfn resource uses ref property, whereas the high-level VPC construct uses vpc_id property.

my_vpc = _ec2.Vpc(
tgw = _ec2.CfnTransitGateway(...)
tgw_attachment = _ec2.CfnTransitGatewayAttachment(
            self,
            id="tgw-myvpc",
            transit_gateway_id=tgw.ref,
            vpc_id=my_vpc.vpc_id,
            ...
)

Upvotes: 7

Related Questions