Class Fn
CloudFormation intrinsic functions.
public class Fn : DeputyBase
- Inheritance
-
Fn
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"
} }
}
});
Remarks
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
ExampleMetadata: infused
Methods
Base64(string)
The intrinsic function Fn::Base64
returns the Base64 representation of the input string.
public static string Base64(string data)
Parameters
data
stringThe string value you want to convert to Base64.
Returns
- 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
stringThe user-specified default Cidr address block.
count
doubleThe number of subnets' Cidr block wanted.
sizeMask
stringThe digit covered in the subnet.
Returns
- string[]
a token represented as a string
ConditionAnd(params 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
string[]A list of strings, such as "A", "B", "C".
value
stringA 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
string[]A list of strings, such as "A", "B", "C".
value
stringA 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
string[]A list of strings, such as "A", "B", "C".
stringsToMatch
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
objectA value of any type that you want to compare.
rhs
objectA 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
stringA reference to a condition in the Conditions section.
valueIfTrue
objectA value to be returned if the specified condition evaluates to true.
valueIfFalse
objectA 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
ICfnConditionExpressionA 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(params 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
Returns
- 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
stringThe logical name (also called logical ID) of the resource that contains the attribute that you want.
attributeName
stringThe 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
stringThe name of the region for which you want to get the Availability Zones.
Returns
- 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
Returns
- 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
stringThe stack output value that you want to import.
Returns
- 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
stringThe value you want to occur between fragments.
listOfValues
string[]The list of values you want combined.
Returns
- 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
stringthe url to parse.
Returns
Ref(string)
The Ref
intrinsic function returns the value of the specified parameter or resource.
public static string Ref(string logicalName)
Parameters
logicalName
stringThe logical name of a parameter/resource for which you want to retrieve its value.
Returns
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
stringAn AWS-specific parameter type, such as AWS::EC2::SecurityGroup::Id or AWS::EC2::VPC::Id.
Returns
- 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
doubleThe index of the object to retrieve.
array
string[]The list of objects to select from.
Returns
- string
a token represented as a string
Split(string, string, double?)
Split a string token into a token list of string values.
public static string[] Split(string delimiter, string source, double? assumedLength = null)
Parameters
delimiter
stringA string value that determines where the source string is divided.
source
stringThe string value that you want to split.
assumedLength
double?The length of the list that will be produced by splitting.
Returns
- 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
stringA string with variables that AWS CloudFormation substitutes with their associated values at runtime.
variables
IDictionary<string, string>The name of a variable that you included in the String parameter.
Returns
- 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
stringThe name of the macro to perform the processing.
parameters
IDictionary<string, object>The parameters to be passed to the macro.
Returns
- IResolvable
a token representing the transform expression
Remarks
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
stringThe name of a parameter for which you want to retrieve attribute values.
attribute
stringThe name of an attribute from which you want to retrieve a value.
Returns
- 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
stringAn AWS-specific parameter type, such as AWS::EC2::SecurityGroup::Id or AWS::EC2::VPC::Id.
attribute
stringThe name of an attribute from which you want to retrieve a value.
Returns
- string[]
a token represented as a string array