Class Fn
CloudFormation intrinsic functions.
Namespace: Amazon.CDK
Assembly: Amazon.CDK.Lib.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;
Bucket destinationBucket;
var myBucketDeployment = new BucketDeployment(this, "DeployMeWithoutExtractingFilesOnDestination", new BucketDeploymentProps {
Sources = new [] { Source.Asset(Join(__dirname, "my-website")) },
DestinationBucket = destinationBucket,
Extract = false
});
new CfnOutput(this, "ObjectKey", new CfnOutputProps {
Value = Fn.Select(0, myBucketDeployment.ObjectKeys)
});
Synopsis
Methods
| Base64(string) | The intrinsic function |
| Cidr(string, double, string?) | The intrinsic function |
| 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. |
| 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(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. |
| FindInMap(string, string, string, string?) | The intrinsic function |
| GetAtt(string, string) | The |
| GetAzs(string?) | The intrinsic function |
| ImportListValue(string, double, string?) | Like |
| ImportValue(string) | The intrinsic function |
| Join(string, string[]) | The intrinsic function |
| Len(object) | The intrinsic function |
| ParseDomainName(string) | Given an url, parse the domain name. |
| Ref(string) | The |
| RefAll(string) | Returns all values for a specified parameter type. |
| Select(double, string[]) | The intrinsic function |
| Split(string, string, double?) | Split a string token into a token list of string values. |
| Sub(string, IDictionary<string, string>?) | The intrinsic function |
| ToJsonString(object) | The |
| Transform(string, IDictionary<string, object>) | Creates a token representing the |
| 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. |
Methods
Base64(string)
The intrinsic function Fn::Base64 returns the Base64 representation of the input string.
public static string Base64(string data)
Parameters
- data string
The string value you want to convert to Base64.
Returns
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 string
The user-specified default Cidr address block.
- count double
The number of subnets' Cidr block wanted.
- sizeMask string
The digit covered in the subnet.
Returns
string[]
a token represented as a string
Remarks
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
ExampleMetadata: infused
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
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 string
A string, such as "A", that you want to compare against a list of strings.
Returns
an FnCondition token
Remarks
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
ExampleMetadata: infused
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 string
A string, such as "A", that you want to compare against a list of strings.
Returns
an FnCondition token
Remarks
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
ExampleMetadata: infused
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
an FnCondition token
Remarks
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
ExampleMetadata: infused
ConditionEquals(object, object)
Compares if two values are equal.
public static ICfnRuleConditionExpression ConditionEquals(object lhs, object rhs)
Parameters
- lhs object
A value of any type that you want to compare.
- rhs object
A value of any type that you want to compare.
Returns
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 string
A reference to a condition in the Conditions section.
- valueIfTrue object
A value to be returned if the specified condition evaluates to true.
- valueIfFalse object
A value to be returned if the specified condition evaluates to false.
Returns
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::Equalsthat evaluates to true or false.
Returns
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
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, 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, string? defaultValue = null)
Parameters
Returns
a token represented as a string
Remarks
Warning: do not use with lazy mappings as this function will not guarentee a lazy mapping to render in the template.
Prefer to use CfnMapping.findInMap in general.
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 string
The logical name (also called logical ID) of the resource that contains the attribute that you want.
- attributeName string
The name of the resource-specific attribute whose value you want.
Returns
an IResolvable object
Remarks
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
ExampleMetadata: infused
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 string
The 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 string
The stack output value that you want to import.
Returns
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 string
The value you want to occur between fragments.
- listOfValues string[]
The list of values you want combined.
Returns
a token represented as a string
Remarks
If a delimiter is the empty string, the set of values are concatenated with no delimiter.
Len(object)
The intrinsic function Fn::Length returns the number of elements within an array or an intrinsic function that returns an array.
public static double Len(object array)
Parameters
- array object
The array you want to return the number of elements from.
Returns
Remarks
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
ExampleMetadata: infused
ParseDomainName(string)
Given an url, parse the domain name.
public static string ParseDomainName(string url)
Parameters
- url string
the url to parse.
Returns
Remarks
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
ExampleMetadata: infused
Ref(string)
The Ref intrinsic function returns the value of the specified parameter or resource.
public static string Ref(string logicalName)
Parameters
- logicalName string
The 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 parameter/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 string
An AWS-specific parameter type, such as AWS::EC2::SecurityGroup::Id or AWS::EC2::VPC::Id.
Returns
string[]
a token represented as a string array
Remarks
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
ExampleMetadata: infused
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 double
The index of the object to retrieve.
- array string[]
The list of objects to select from.
Returns
a token represented as a string
Remarks
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
ExampleMetadata: infused
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 string
A string value that determines where the source string is divided.
- source string
The 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 string
A 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
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.
ToJsonString(object)
The Fn::ToJsonString intrinsic function converts an object or array to its corresponding JSON string.
public static string ToJsonString(object @object)
Parameters
- object object
The object or array to stringify.
Returns
Remarks
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
ExampleMetadata: infused
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 string
The name of the macro to perform the processing.
- parameters IDictionary<string, object>
The parameters to be passed to the macro.
Returns
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 string
The name of a parameter for which you want to retrieve attribute values.
- attribute string
The name of an attribute from which you want to retrieve a value.
Returns
a token represented as a string
Remarks
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
ExampleMetadata: infused
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 string
An AWS-specific parameter type, such as AWS::EC2::SecurityGroup::Id or AWS::EC2::VPC::Id.
- attribute string
The name of an attribute from which you want to retrieve a value.
Returns
string[]
a token represented as a string array
Remarks
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
ExampleMetadata: infused