Skip to content
v2.274.0

Fn Class ​

CloudFormation intrinsic functions.

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

Example ​

ts
import * as cdk from 'aws-cdk-lib';

declare const destinationBucket: s3.Bucket;

const myBucketDeployment = new s3deploy.BucketDeployment(this, 'DeployMeWithoutExtractingFilesOnDestination', {
  sources: [s3deploy.Source.asset(path.join(__dirname, 'my-website'))],
  destinationBucket,
  extract: false,
});

new cdk.CfnOutput(this, 'ObjectKey', {
  value: cdk.Fn.select(0, myBucketDeployment.objectKeys),
});

Methods ​

base64(data: string): string@staticmethod def base64(data: str) -> strpublic static String base64(String data)public static string Base64(string data)func Base64(Data *string) *stringstatic#
The intrinsic function ``Fn::Base64`` returns the Base64 representation of the input string.

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

1 parameter · returns

Parameters

  • datadatadatadataData — The string value you want to convert to Base64.

Returns: a token represented as a string

cidr(ipBlock: string, count: number, sizeMask?: string): string[]@staticmethod def cidr(ip_block: str, count: int | float, size_mask: typing.Optional[str] = None) -> typing.List[str]public static List<String> cidr(String ipBlock, Number count, String sizeMask)public static string[] Cidr(string ipBlock, double count, string? sizeMask = null)func Cidr(IpBlock *string, Count *float64, SizeMask *string) *[]*stringstatic#
The intrinsic function ``Fn::Cidr`` returns the specified Cidr address block.
3 parameters · returns

Parameters

  • ipBlockip_blockipBlockipBlockIpBlock — The user-specified default Cidr address block.
  • countcountcountcountCount — The number of subnets' Cidr block wanted.
  • sizeMasksize_masksizeMasksizeMaskSizeMask — The digit covered in the subnet.

Returns: a token represented as a string

conditionAnd(...conditions: ICfnConditionExpression[]): ICfnRuleConditionExpression@staticmethod def condition_and(conditions: ICfnConditionExpression) -> ICfnRuleConditionExpressionpublic static ICfnRuleConditionExpression conditionAnd(ICfnConditionExpression conditions)public static ICfnRuleConditionExpression ConditionAnd(ICfnConditionExpression conditions)func ConditionAnd(Conditions ICfnConditionExpression) ICfnRuleConditionExpressionstatic#
Returns true if all the specified conditions evaluate to true, or returns false if any one of the conditions evaluates to false.

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

1 parameter · returns

Parameters

  • conditionsconditionsconditionsconditionsConditions — conditions to AND.

Returns: an FnCondition token

conditionContains(listOfStrings: string[], value: string): ICfnRuleConditionExpression@staticmethod def condition_contains(list_of_strings: typing.List[str], value: str) -> ICfnRuleConditionExpressionpublic static ICfnRuleConditionExpression conditionContains(List<String> listOfStrings, String value)public static ICfnRuleConditionExpression ConditionContains(string[] listOfStrings, string value)func ConditionContains(ListOfStrings *[]*string, Value *string) ICfnRuleConditionExpressionstatic#
Returns true if a specified string matches at least one value in a list of strings.
2 parameters · returns

Parameters

  • listOfStringslist_of_stringslistOfStringslistOfStringsListOfStrings — A list of strings, such as "A", "B", "C".
  • valuevaluevaluevalueValue — A string, such as "A", that you want to compare against a list of strings.

Returns: an FnCondition token

conditionEachMemberEquals(listOfStrings: string[], value: string): ICfnRuleConditionExpression@staticmethod def condition_each_member_equals(list_of_strings: typing.List[str], value: str) -> ICfnRuleConditionExpressionpublic static ICfnRuleConditionExpression conditionEachMemberEquals(List<String> listOfStrings, String value)public static ICfnRuleConditionExpression ConditionEachMemberEquals(string[] listOfStrings, string value)func ConditionEachMemberEquals(ListOfStrings *[]*string, Value *string) ICfnRuleConditionExpressionstatic#
Returns true if a specified string matches all values in a list.
2 parameters · returns

Parameters

  • listOfStringslist_of_stringslistOfStringslistOfStringsListOfStrings — A list of strings, such as "A", "B", "C".
  • valuevaluevaluevalueValue — A string, such as "A", that you want to compare against a list of strings.

Returns: an FnCondition token

conditionEachMemberIn(stringsToCheck: string[], stringsToMatch: string[]): ICfnRuleConditionExpression@staticmethod def condition_each_member_in(strings_to_check: typing.List[str], strings_to_match: typing.List[str]) -> ICfnRuleConditionExpressionpublic static ICfnRuleConditionExpression conditionEachMemberIn(List<String> stringsToCheck, List<String> stringsToMatch)public static ICfnRuleConditionExpression ConditionEachMemberIn(string[] stringsToCheck, string[] stringsToMatch)func ConditionEachMemberIn(StringsToCheck *[]*string, StringsToMatch *[]*string) ICfnRuleConditionExpressionstatic#
Returns true if each member in a list of strings matches at least one value in a second list of strings.
2 parameters · returns

Parameters

  • stringsToCheckstrings_to_checkstringsToCheckstringsToCheckStringsToCheck — A list of strings, such as "A", "B", "C".
  • stringsToMatchstrings_to_matchstringsToMatchstringsToMatchStringsToMatch — A list of strings, such as "A", "B", "C".

Returns: an FnCondition token

conditionEquals(lhs: any, rhs: any): ICfnRuleConditionExpression@staticmethod def condition_equals(lhs: Any, rhs: Any) -> ICfnRuleConditionExpressionpublic static ICfnRuleConditionExpression conditionEquals(Object lhs, Object rhs)public static ICfnRuleConditionExpression ConditionEquals(object lhs, object rhs)func ConditionEquals(Lhs interface{}, Rhs interface{}) ICfnRuleConditionExpressionstatic#
Compares if two values are equal.

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

2 parameters · returns

Parameters

  • lhslhslhslhsLhs — A value of any type that you want to compare.
  • rhsrhsrhsrhsRhs — A value of any type that you want to compare.

Returns: an FnCondition token

conditionIf(conditionId: string, valueIfTrue: any, valueIfFalse: any): ICfnRuleConditionExpression@staticmethod def condition_if(condition_id: str, value_if_true: Any, value_if_false: Any) -> ICfnRuleConditionExpressionpublic static ICfnRuleConditionExpression conditionIf(String conditionId, Object valueIfTrue, Object valueIfFalse)public static ICfnRuleConditionExpression ConditionIf(string conditionId, object valueIfTrue, object valueIfFalse)func ConditionIf(ConditionId *string, ValueIfTrue interface{}, ValueIfFalse interface{}) ICfnRuleConditionExpressionstatic#
Returns one value if the specified condition evaluates to true and another value if the specified condition evaluates to false.
notes · 3 parameters · returns

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.

Parameters

  • conditionIdcondition_idconditionIdconditionIdConditionId — A reference to a condition in the Conditions section.
  • valueIfTruevalue_if_truevalueIfTruevalueIfTrueValueIfTrue — A value to be returned if the specified condition evaluates to true.
  • valueIfFalsevalue_if_falsevalueIfFalsevalueIfFalseValueIfFalse — A value to be returned if the specified condition evaluates to false.

Returns: an FnCondition token

conditionNot(condition: ICfnConditionExpression): ICfnRuleConditionExpression@staticmethod def condition_not(condition: ICfnConditionExpression) -> ICfnRuleConditionExpressionpublic static ICfnRuleConditionExpression conditionNot(ICfnConditionExpression condition)public static ICfnRuleConditionExpression ConditionNot(ICfnConditionExpression condition)func ConditionNot(Condition ICfnConditionExpression) ICfnRuleConditionExpressionstatic#
Returns true for a condition that evaluates to false or returns false for a condition that evaluates to true.

Fn::Not acts as a NOT operator.

1 parameter · returns

Parameters

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

Returns: an FnCondition token

conditionOr(...conditions: ICfnConditionExpression[]): ICfnRuleConditionExpression@staticmethod def condition_or(conditions: ICfnConditionExpression) -> ICfnRuleConditionExpressionpublic static ICfnRuleConditionExpression conditionOr(ICfnConditionExpression conditions)public static ICfnRuleConditionExpression ConditionOr(ICfnConditionExpression conditions)func ConditionOr(Conditions ICfnConditionExpression) ICfnRuleConditionExpressionstatic#
Returns true if any one of the specified conditions evaluate to true, or returns false if all of the conditions evaluates to false.

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

1 parameter · returns

Parameters

  • conditionsconditionsconditionsconditionsConditions — conditions that evaluates to true or false.

Returns: an FnCondition token

findInMap(mapName: string, topLevelKey: string, secondLevelKey: string, defaultValue?: string): string@staticmethod def find_in_map(map_name: str, top_level_key: str, second_level_key: str, default_value: typing.Optional[str] = None) -> strpublic static String findInMap(String mapName, String topLevelKey, String secondLevelKey, String defaultValue)public static string FindInMap(string mapName, string topLevelKey, string secondLevelKey, string? defaultValue = null)func FindInMap(MapName *string, TopLevelKey *string, SecondLevelKey *string, DefaultValue *string) *stringstatic#
The intrinsic function ``Fn::FindInMap`` returns the value corresponding to keys in a two-level map that is declared in the Mappings section.

Warning: do not use with lazy mappings as this function will not guarantee a lazy mapping to render in the template. Prefer to use CfnMapping.findInMap in general.

returns

Returns: a token represented as a string

getAtt(logicalNameOfResource: string, attributeName: string): IResolvable@staticmethod def get_att(logical_name_of_resource: str, attribute_name: str) -> IResolvablepublic static IResolvable getAtt(String logicalNameOfResource, String attributeName)public static IResolvable GetAtt(string logicalNameOfResource, string attributeName)func GetAtt(LogicalNameOfResource *string, AttributeName *string) IResolvablestatic#
The ``Fn::GetAtt`` intrinsic function returns the value of an attribute from a resource in the template.
2 parameters · returns

Parameters

  • logicalNameOfResourcelogical_name_of_resourcelogicalNameOfResourcelogicalNameOfResourceLogicalNameOfResource — The logical name (also called logical ID) of the resource that contains the attribute that you want.
  • attributeNameattribute_nameattributeNameattributeNameAttributeName — The name of the resource-specific attribute whose value you want.

Returns: an IResolvable object

getAzs(region?: string): string[]@staticmethod def get_azs(region: typing.Optional[str] = None) -> typing.List[str]public static List<String> getAzs(String region)public static string[] GetAzs(string? region = null)func GetAzs(Region *string) *[]*stringstatic#
The intrinsic function ``Fn::GetAZs`` returns an array that lists Availability Zones for a specified region.
notes · 1 parameter · returns

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.

Parameters

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

Returns: a token represented as a string array

getStackOutput(stackName: string, outputName: string, region?: string, roleArn?: string): string@staticmethod def get_stack_output(stack_name: str, output_name: str, region: typing.Optional[str] = None, role_arn: typing.Optional[str] = None) -> strpublic static String getStackOutput(String stackName, String outputName, String region, String roleArn)public static string GetStackOutput(string stackName, string outputName, string? region = null, string? roleArn = null)func GetStackOutput(StackName *string, OutputName *string, Region *string, RoleArn *string) *stringstatic#
The intrinsic function `Fn::GetStackOutput` returns the value of an output from another stack.

This is similar to Fn::ImportValue, but it can reference a normal output, without the need to export anything. As with Fn::ImportValue, you typically use this function to create cross-stack references.

4 parameters

Parameters

  • stackNamestack_namestackNamestackNameStackName — The name of the producer stack.
  • outputNameoutput_nameoutputNameoutputNameOutputName — The name of the output to get the value from.
  • regionregionregionregionRegion — The region where the producer stack is deployed.
  • roleArnrole_arnroleArnroleArnRoleArn — The role to be used when describing the producer stack.
importListValue(sharedValueToImport: string, assumedLength: number, delimiter?: string): string[]@staticmethod def import_list_value(shared_value_to_import: str, assumed_length: int | float, delimiter: typing.Optional[str] = None) -> typing.List[str]public static List<String> importListValue(String sharedValueToImport, Number assumedLength, String delimiter)public static string[] ImportListValue(string sharedValueToImport, double assumedLength, string? delimiter = null)func ImportListValue(SharedValueToImport *string, AssumedLength *float64, Delimiter *string) *[]*stringstatic#
Like `Fn.importValue`, but import a list with a known length.
notes

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(sharedValueToImport: string): string@staticmethod def import_value(shared_value_to_import: str) -> strpublic static String importValue(String sharedValueToImport)public static string ImportValue(string sharedValueToImport)func ImportValue(SharedValueToImport *string) *stringstatic#
The intrinsic function ``Fn::ImportValue`` returns the value of an output exported by another stack.

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.

1 parameter · returns

Parameters

  • sharedValueToImportshared_value_to_importsharedValueToImportsharedValueToImportSharedValueToImport — The stack output value that you want to import.

Returns: a token represented as a string

join(delimiter: string, listOfValues: string[]): string@staticmethod def join(delimiter: str, list_of_values: typing.List[str]) -> strpublic static String join(String delimiter, List<String> listOfValues)public static string Join(string delimiter, string[] listOfValues)func Join(Delimiter *string, ListOfValues *[]*string) *stringstatic#
The intrinsic function ``Fn::Join`` appends a set of values into a single value, separated by the specified delimiter.

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

2 parameters · returns

Parameters

  • delimiterdelimiterdelimiterdelimiterDelimiter — The value you want to occur between fragments.
  • listOfValueslist_of_valueslistOfValueslistOfValuesListOfValues — The list of values you want combined.

Returns: a token represented as a string

len(array: any): number@staticmethod def len(array: Any) -> int | floatpublic static Number len(Object array)public static double Len(object array)func Len(Array interface{}) *float64static#
The intrinsic function `Fn::Length` returns the number of elements within an array or an intrinsic function that returns an array.
1 parameter

Parameters

  • arrayarrayarrayarrayArray — The array you want to return the number of elements from.
parseDomainName(url: string): string@staticmethod def parse_domain_name(url: str) -> strpublic static String parseDomainName(String url)public static string ParseDomainName(string url)func ParseDomainName(Url *string) *stringstatic#
Given an url, parse the domain name.
1 parameter

Parameters

  • urlurlurlurlUrl — the url to parse.
ref(logicalName: string): string@staticmethod def ref(logical_name: str) -> strpublic static String ref(String logicalName)public static string Ref(string logicalName)func Ref(LogicalName *string) *stringstatic#
The ``Ref`` intrinsic function returns the value of the specified parameter or resource.

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

1 parameter

Parameters

  • logicalNamelogical_namelogicalNamelogicalNameLogicalName — The logical name of a parameter/resource for which you want to retrieve its value.
refAll(parameterType: string): string[]@staticmethod def ref_all(parameter_type: str) -> typing.List[str]public static List<String> refAll(String parameterType)public static string[] RefAll(string parameterType)func RefAll(ParameterType *string) *[]*stringstatic#
Returns all values for a specified parameter type.
1 parameter · returns

Parameters

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

Returns: a token represented as a string array

select(index: number, array: string[]): string@staticmethod def select(index: int | float, array: typing.List[str]) -> strpublic static String select(Number index, List<String> array)public static string Select(double index, string[] array)func Select(Index *float64, Array *[]*string) *stringstatic#
The intrinsic function ``Fn::Select`` returns a single object from a list of objects by index.
2 parameters · returns

Parameters

  • indexindexindexindexIndex — The index of the object to retrieve.
  • arrayarrayarrayarrayArray — The list of objects to select from.

Returns: a token represented as a string

split(delimiter: string, source: string, assumedLength?: number): string[]@staticmethod def split(delimiter: str, source: str, assumed_length: typing.Optional[int | float] = None) -> typing.List[str]public static List<String> split(String delimiter, String source, Number assumedLength)public static string[] Split(string delimiter, string source, double? assumedLength = null)func Split(Delimiter *string, Source *string, AssumedLength *float64) *[]*stringstatic#
Split a string token into a token list of string values.
notes · 3 parameters · returns

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:

  • You must use Fn.select(i, list) to pick elements out of the list (you must not use list[i]).
  • You cannot add elements to the list, remove elements from the list, combine two such lists together, or take a slice of the list.
  • You cannot pass the list to constructs that do any of the above.

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.

Parameters

  • delimiterdelimiterdelimiterdelimiterDelimiter — A string value that determines where the source string is divided.
  • sourcesourcesourcesourceSource — The string value that you want to split.
  • assumedLengthassumed_lengthassumedLengthassumedLengthAssumedLength — The length of the list that will be produced by splitting.

Returns: a token represented as a string array

sub(body: string, variables?: { [key: string]: string }): string@staticmethod def sub(body: str, variables: typing.Optional[typing.Mapping[str, str]] = None) -> strpublic static String sub(String body, Map<String, String> variables)public static string Sub(string body, IDictionary<string, string>? variables = null)func Sub(Body *string, Variables *map[string]*string) *stringstatic#
The intrinsic function ``Fn::Sub`` substitutes variables in an input string with values that you specify.

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.

2 parameters · returns

Parameters

  • bodybodybodybodyBody — A string with variables that AWS CloudFormation substitutes with their associated values at runtime.
  • variablesvariablesvariablesvariablesVariables — The name of a variable that you included in the String parameter.

Returns: a token represented as a string

toJsonString(object: any): string@staticmethod def to_json_string(object: Any) -> strpublic static String toJsonString(Object object)public static string ToJsonString(object object)func ToJsonString(Object interface{}) *stringstatic#
The `Fn::ToJsonString` intrinsic function converts an object or array to its corresponding JSON string.
1 parameter

Parameters

  • objectobjectobjectobjectObject — The object or array to stringify.
transform(macroName: string, parameters: { [key: string]: any }): IResolvable@staticmethod def transform(macro_name: str, parameters: typing.Mapping[str, Any]) -> IResolvablepublic static IResolvable transform(String macroName, Map<String, Object> parameters)public static IResolvable Transform(string macroName, IDictionary<string, object> parameters)func Transform(MacroName *string, Parameters *map[string]interface{}) IResolvablestatic#
Creates a token representing the ``Fn::Transform`` expression.
2 parameters · returns

Parameters

  • macroNamemacro_namemacroNamemacroNameMacroName — The name of the macro to perform the processing.
  • parametersparametersparametersparametersParameters — The parameters to be passed to the macro.

Returns: a token representing the transform expression

valueOf(parameterOrLogicalId: string, attribute: string): string@staticmethod def value_of(parameter_or_logical_id: str, attribute: str) -> strpublic static String valueOf(String parameterOrLogicalId, String attribute)public static string ValueOf(string parameterOrLogicalId, string attribute)func ValueOf(ParameterOrLogicalId *string, Attribute *string) *stringstatic#
Returns an attribute value or list of values for a specific parameter and attribute.
2 parameters · returns

Parameters

  • parameterOrLogicalIdparameter_or_logical_idparameterOrLogicalIdparameterOrLogicalIdParameterOrLogicalId — The name of a parameter for which you want to retrieve attribute values.
  • attributeattributeattributeattributeAttribute — The name of an attribute from which you want to retrieve a value.

Returns: a token represented as a string

valueOfAll(parameterType: string, attribute: string): string[]@staticmethod def value_of_all(parameter_type: str, attribute: str) -> typing.List[str]public static List<String> valueOfAll(String parameterType, String attribute)public static string[] ValueOfAll(string parameterType, string attribute)func ValueOfAll(ParameterType *string, Attribute *string) *[]*stringstatic#
Returns a list of all attribute values for a given parameter type and attribute.
2 parameters · returns

Parameters

  • parameterTypeparameter_typeparameterTypeparameterTypeParameterType — An AWS-specific parameter type, such as AWS::EC2::SecurityGroup::Id or AWS::EC2::VPC::Id.
  • attributeattributeattributeattributeAttribute — The name of an attribute from which you want to retrieve a value.

Returns: a token represented as a string array