Show / Hide Table of Contents

Class Fn

CloudFormation intrinsic functions.

Inheritance
System.Object
Fn
Namespace: Amazon.CDK
Assembly: Amazon.CDK.dll
Syntax (csharp)
public class Fn : DeputyBase
Syntax (vb)
Public Class Fn
    Inherits DeputyBase
Remarks

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html

ExampleMetadata: infused

Examples
using Amazon.CDK;

Portfolio portfolio;
CloudFormationProduct product;


portfolio.ConstrainCloudFormationParameters(product, new CloudFormationRuleConstraintOptions {
    Rule = new TemplateRule {
        RuleName = "testInstanceType",
        Condition = Fn.ConditionEquals(Fn.Ref("Environment"), "test"),
        Assertions = new [] { new TemplateRuleAssertion {
            Assert = Fn.ConditionContains(new [] { "t2.micro", "t2.small" }, Fn.Ref("InstanceType")),
            Description = "For test environment, the instance type should be small"
        } }
    }
});

Synopsis

Constructors

Fn(ByRefValue)

Used by jsii to construct an instance of this class from a Javascript-owned object reference

Fn(DeputyBase.DeputyProps)

Used by jsii to construct an instance of this class from DeputyProps

Methods

Base64(String)

The intrinsic function Fn::Base64 returns the Base64 representation of the input string.

Cidr(String, Double, String)

The intrinsic function Fn::Cidr returns the specified Cidr address block.

ConditionAnd(ICfnConditionExpression[])

Returns true if all the specified conditions evaluate to true, or returns false if any one of the conditions evaluates to false.

ConditionContains(String[], String)

Returns true if a specified string matches at least one value in a list of strings.

ConditionEachMemberEquals(String[], String)

Returns true if a specified string matches all values in a list.

ConditionEachMemberIn(String[], String[])

Returns true if each member in a list of strings matches at least one value in a second list of strings.

ConditionEquals(Object, Object)

Compares if two values are equal.

ConditionIf(String, Object, Object)

Returns one value if the specified condition evaluates to true and another value if the specified condition evaluates to false.

ConditionNot(ICfnConditionExpression)

Returns true for a condition that evaluates to false or returns false for a condition that evaluates to true.

ConditionOr(ICfnConditionExpression[])

Returns true if any one of the specified conditions evaluate to true, or returns false if all of the conditions evaluates to false.

FindInMap(String, String, String)

The intrinsic function Fn::FindInMap returns the value corresponding to keys in a two-level map that is declared in the Mappings section.

GetAtt(String, String)

The Fn::GetAtt intrinsic function returns the value of an attribute from a resource in the template.

GetAzs(String)

The intrinsic function Fn::GetAZs returns an array that lists Availability Zones for a specified region.

ImportListValue(String, Double, String)

Like Fn.importValue, but import a list with a known length.

ImportValue(String)

The intrinsic function Fn::ImportValue returns the value of an output exported by another stack.

Join(String, String[])

The intrinsic function Fn::Join appends a set of values into a single value, separated by the specified delimiter.

ParseDomainName(String)

Given an url, parse the domain name.

Ref(String)

The Ref intrinsic function returns the value of the specified parameter or resource.

RefAll(String)

Returns all values for a specified parameter type.

Select(Double, String[])

The intrinsic function Fn::Select returns a single object from a list of objects by index.

Split(String, String, Nullable<Double>)

Split a string token into a token list of string values.

Sub(String, IDictionary<String, String>)

The intrinsic function Fn::Sub substitutes variables in an input string with values that you specify.

Transform(String, IDictionary<String, Object>)

Creates a token representing the Fn::Transform expression.

ValueOf(String, String)

Returns an attribute value or list of values for a specific parameter and attribute.

ValueOfAll(String, String)

Returns a list of all attribute values for a given parameter type and attribute.

Constructors

Fn(ByRefValue)

Used by jsii to construct an instance of this class from a Javascript-owned object reference

protected Fn(ByRefValue reference)
Parameters
reference Amazon.JSII.Runtime.Deputy.ByRefValue

The Javascript-owned object reference

Fn(DeputyBase.DeputyProps)

Used by jsii to construct an instance of this class from DeputyProps

protected Fn(DeputyBase.DeputyProps props)
Parameters
props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps

The deputy props

Methods

Base64(String)

The intrinsic function Fn::Base64 returns the Base64 representation of the input string.

public static string Base64(string data)
Parameters
data System.String

The string value you want to convert to Base64.

Returns

System.String

a token represented as a string

Remarks

This function is typically used to pass encoded data to Amazon EC2 instances by way of the UserData property.

Cidr(String, Double, String)

The intrinsic function Fn::Cidr returns the specified Cidr address block.

public static string[] Cidr(string ipBlock, double count, string sizeMask = null)
Parameters
ipBlock System.String

The user-specified default Cidr address block.

count System.Double

The number of subnets' Cidr block wanted.

sizeMask System.String

The digit covered in the subnet.

Returns

System.String[]

a token represented as a string

ConditionAnd(ICfnConditionExpression[])

Returns true if all the specified conditions evaluate to true, or returns false if any one of the conditions evaluates to false.

public static ICfnRuleConditionExpression ConditionAnd(params ICfnConditionExpression[] conditions)
Parameters
conditions ICfnConditionExpression[]

conditions to AND.

Returns

ICfnRuleConditionExpression

an FnCondition token

Remarks

Fn::And acts as an AND operator. The minimum number of conditions that you can include is 1.

ConditionContains(String[], String)

Returns true if a specified string matches at least one value in a list of strings.

public static ICfnRuleConditionExpression ConditionContains(string[] listOfStrings, string value)
Parameters
listOfStrings System.String[]

A list of strings, such as "A", "B", "C".

value System.String

A string, such as "A", that you want to compare against a list of strings.

Returns

ICfnRuleConditionExpression

an FnCondition token

ConditionEachMemberEquals(String[], String)

Returns true if a specified string matches all values in a list.

public static ICfnRuleConditionExpression ConditionEachMemberEquals(string[] listOfStrings, string value)
Parameters
listOfStrings System.String[]

A list of strings, such as "A", "B", "C".

value System.String

A string, such as "A", that you want to compare against a list of strings.

Returns

ICfnRuleConditionExpression

an FnCondition token

ConditionEachMemberIn(String[], String[])

Returns true if each member in a list of strings matches at least one value in a second list of strings.

public static ICfnRuleConditionExpression ConditionEachMemberIn(string[] stringsToCheck, string[] stringsToMatch)
Parameters
stringsToCheck System.String[]

A list of strings, such as "A", "B", "C".

stringsToMatch System.String[]

A list of strings, such as "A", "B", "C".

Returns

ICfnRuleConditionExpression

an FnCondition token

ConditionEquals(Object, Object)

Compares if two values are equal.

public static ICfnRuleConditionExpression ConditionEquals(object lhs, object rhs)
Parameters
lhs System.Object

A value of any type that you want to compare.

rhs System.Object

A value of any type that you want to compare.

Returns

ICfnRuleConditionExpression

an FnCondition token

Remarks

Returns true if the two values are equal or false if they aren't.

ConditionIf(String, Object, Object)

Returns one value if the specified condition evaluates to true and another value if the specified condition evaluates to false.

public static ICfnRuleConditionExpression ConditionIf(string conditionId, object valueIfTrue, object valueIfFalse)
Parameters
conditionId System.String

A reference to a condition in the Conditions section.

valueIfTrue System.Object

A value to be returned if the specified condition evaluates to true.

valueIfFalse System.Object

A value to be returned if the specified condition evaluates to false.

Returns

ICfnRuleConditionExpression

an FnCondition token

Remarks

Currently, AWS CloudFormation supports the Fn::If intrinsic function in the metadata attribute, update policy attribute, and property values in the Resources section and Outputs sections of a template. You can use the AWS::NoValue pseudo parameter as a return value to remove the corresponding property.

ConditionNot(ICfnConditionExpression)

Returns true for a condition that evaluates to false or returns false for a condition that evaluates to true.

public static ICfnRuleConditionExpression ConditionNot(ICfnConditionExpression condition)
Parameters
condition ICfnConditionExpression

A condition such as Fn::Equals that evaluates to true or false.

Returns

ICfnRuleConditionExpression

an FnCondition token

Remarks

Fn::Not acts as a NOT operator.

ConditionOr(ICfnConditionExpression[])

Returns true if any one of the specified conditions evaluate to true, or returns false if all of the conditions evaluates to false.

public static ICfnRuleConditionExpression ConditionOr(params ICfnConditionExpression[] conditions)
Parameters
conditions ICfnConditionExpression[]

conditions that evaluates to true or false.

Returns

ICfnRuleConditionExpression

an FnCondition token

Remarks

Fn::Or acts as an OR operator. The minimum number of conditions that you can include is 1.

FindInMap(String, String, String)

The intrinsic function Fn::FindInMap returns the value corresponding to keys in a two-level map that is declared in the Mappings section.

public static string FindInMap(string mapName, string topLevelKey, string secondLevelKey)
Parameters
mapName System.String
topLevelKey System.String
secondLevelKey System.String
Returns

System.String

a token represented as a string

GetAtt(String, String)

The Fn::GetAtt intrinsic function returns the value of an attribute from a resource in the template.

public static IResolvable GetAtt(string logicalNameOfResource, string attributeName)
Parameters
logicalNameOfResource System.String

The logical name (also called logical ID) of the resource that contains the attribute that you want.

attributeName System.String

The name of the resource-specific attribute whose value you want.

Returns

IResolvable

an IResolvable object

GetAzs(String)

The intrinsic function Fn::GetAZs returns an array that lists Availability Zones for a specified region.

public static string[] GetAzs(string region = null)
Parameters
region System.String

The name of the region for which you want to get the Availability Zones.

Returns

System.String[]

a token represented as a string array

Remarks

Because customers have access to different Availability Zones, the intrinsic function Fn::GetAZs enables template authors to write templates that adapt to the calling user's access. That way you don't have to hard-code a full list of Availability Zones for a specified region.

ImportListValue(String, Double, String)

Like Fn.importValue, but import a list with a known length.

public static string[] ImportListValue(string sharedValueToImport, double assumedLength, string delimiter = null)
Parameters
sharedValueToImport System.String
assumedLength System.Double
delimiter System.String
Returns

System.String[]

Remarks

If you explicitly want a list with an unknown length, call Fn.split(',', Fn.importValue(exportName)). See the documentation of Fn.split to read more about the limitations of using lists of unknown length.

Fn.importListValue(exportName, assumedLength) is the same as Fn.split(',', Fn.importValue(exportName), assumedLength), but easier to read and impossible to forget to pass assumedLength.

ImportValue(String)

The intrinsic function Fn::ImportValue returns the value of an output exported by another stack.

public static string ImportValue(string sharedValueToImport)
Parameters
sharedValueToImport System.String

The stack output value that you want to import.

Returns

System.String

a token represented as a string

Remarks

You typically use this function to create cross-stack references. In the following example template snippets, Stack A exports VPC security group values and Stack B imports them.

Join(String, String[])

The intrinsic function Fn::Join appends a set of values into a single value, separated by the specified delimiter.

public static string Join(string delimiter, string[] listOfValues)
Parameters
delimiter System.String

The value you want to occur between fragments.

listOfValues System.String[]

The list of values you want combined.

Returns

System.String

a token represented as a string

Remarks

If a delimiter is the empty string, the set of values are concatenated with no delimiter.

ParseDomainName(String)

Given an url, parse the domain name.

public static string ParseDomainName(string url)
Parameters
url System.String

the url to parse.

Returns

System.String

Ref(String)

The Ref intrinsic function returns the value of the specified parameter or resource.

public static string Ref(string logicalName)
Parameters
logicalName System.String

The logical name of a parameter/resource for which you want to retrieve its value.

Returns

System.String

Remarks

Note that it doesn't validate the logicalName, it mainly serves paremeter/resource reference defined in a CfnInclude template.

RefAll(String)

Returns all values for a specified parameter type.

public static string[] RefAll(string parameterType)
Parameters
parameterType System.String

An AWS-specific parameter type, such as AWS::EC2::SecurityGroup::Id or AWS::EC2::VPC::Id.

Returns

System.String[]

a token represented as a string array

Select(Double, String[])

The intrinsic function Fn::Select returns a single object from a list of objects by index.

public static string Select(double index, string[] array)
Parameters
index System.Double

The index of the object to retrieve.

array System.String[]

The list of objects to select from.

Returns

System.String

a token represented as a string

Split(String, String, Nullable<Double>)

Split a string token into a token list of string values.

public static string[] Split(string delimiter, string source, Nullable<double> assumedLength = null)
Parameters
delimiter System.String

A string value that determines where the source string is divided.

source System.String

The string value that you want to split.

assumedLength System.Nullable<System.Double>

The length of the list that will be produced by splitting.

Returns

System.String[]

a token represented as a string array

Remarks

Specify the location of splits with a delimiter such as ',' (a comma). Renders to the Fn::Split intrinsic function.

Lists with unknown lengths (default)

Since this function is used to work with deploy-time values, if assumedLength is not given the CDK cannot know the length of the resulting list at synthesis time. This brings the following restrictions:

    The only valid operation with such a tokenized list is to pass it unmodified to a CloudFormation Resource construct.

    Lists with assumed lengths

    Pass assumedLength if you know the length of the list that will be produced by splitting. The actual list length at deploy time may be longer than the number you pass, but not shorter.

    The returned list will look like:

    [Fn.select(0, split), Fn.select(1, split), Fn.select(2, split), ...]

    The restrictions from the section "Lists with unknown lengths" will now be lifted, at the expense of having to know and fix the length of the list.

    Sub(String, IDictionary<String, String>)

    The intrinsic function Fn::Sub substitutes variables in an input string with values that you specify.

    public static string Sub(string body, IDictionary<string, string> variables = null)
    Parameters
    body System.String

    A string with variables that AWS CloudFormation substitutes with their associated values at runtime.

    variables System.Collections.Generic.IDictionary<System.String, System.String>

    The name of a variable that you included in the String parameter.

    Returns

    System.String

    a token represented as a string

    Remarks

    In your templates, you can use this function to construct commands or outputs that include values that aren't available until you create or update a stack.

    Transform(String, IDictionary<String, Object>)

    Creates a token representing the Fn::Transform expression.

    public static IResolvable Transform(string macroName, IDictionary<string, object> parameters)
    Parameters
    macroName System.String

    The name of the macro to perform the processing.

    parameters System.Collections.Generic.IDictionary<System.String, System.Object>

    The parameters to be passed to the macro.

    Returns

    IResolvable

    a token representing the transform expression

    Remarks

    See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-transform.html

    ValueOf(String, String)

    Returns an attribute value or list of values for a specific parameter and attribute.

    public static string ValueOf(string parameterOrLogicalId, string attribute)
    Parameters
    parameterOrLogicalId System.String

    The name of a parameter for which you want to retrieve attribute values.

    attribute System.String

    The name of an attribute from which you want to retrieve a value.

    Returns

    System.String

    a token represented as a string

    ValueOfAll(String, String)

    Returns a list of all attribute values for a given parameter type and attribute.

    public static string[] ValueOfAll(string parameterType, string attribute)
    Parameters
    parameterType System.String

    An AWS-specific parameter type, such as AWS::EC2::SecurityGroup::Id or AWS::EC2::VPC::Id.

    attribute System.String

    The name of an attribute from which you want to retrieve a value.

    Returns

    System.String[]

    a token represented as a string array

    Back to top Generated by DocFX