Fn

class aws_cdk.core.Fn(*args: Any, **kwargs)

Bases: object

CloudFormation intrinsic functions.

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

Static Methods

classmethod base64(data)

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.

Parameters

data (str) – The string value you want to convert to Base64.

Return type

str

Returns

a token represented as a string

classmethod cidr(ip_block, count, size_mask=None)

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

Parameters
  • ip_block (str) – The user-specified default Cidr address block.

  • count (Union[int, float]) – The number of subnets’ Cidr block wanted. Count can be 1 to 256.

  • size_mask (Optional[str]) – The digit covered in the subnet.

Return type

List[str]

Returns

a token represented as a string

classmethod condition_and(*conditions)

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.

Parameters

conditions (ICfnConditionExpression) – conditions to AND.

Return type

ICfnConditionExpression

Returns

an FnCondition token

classmethod condition_contains(list_of_strings, value)

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

Parameters
  • list_of_strings (Sequence[str]) – A list of strings, such as “A”, “B”, “C”.

  • value (str) – A string, such as “A”, that you want to compare against a list of strings.

Return type

ICfnConditionExpression

Returns

an FnCondition token

classmethod condition_each_member_equals(list_of_strings, value)

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

Parameters
  • list_of_strings (Sequence[str]) – A list of strings, such as “A”, “B”, “C”.

  • value (str) – A string, such as “A”, that you want to compare against a list of strings.

Return type

ICfnConditionExpression

Returns

an FnCondition token

classmethod condition_each_member_in(strings_to_check, strings_to_match)

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

Parameters
  • strings_to_check (Sequence[str]) – A list of strings, such as “A”, “B”, “C”. AWS CloudFormation checks whether each member in the strings_to_check parameter is in the strings_to_match parameter.

  • strings_to_match (Sequence[str]) – A list of strings, such as “A”, “B”, “C”. Each member in the strings_to_match parameter is compared against the members of the strings_to_check parameter.

Return type

ICfnConditionExpression

Returns

an FnCondition token

classmethod condition_equals(lhs, rhs)

Compares if two values are equal.

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

Parameters
  • lhs (Any) – A value of any type that you want to compare.

  • rhs (Any) – A value of any type that you want to compare.

Return type

ICfnConditionExpression

Returns

an FnCondition token

classmethod condition_if(condition_id, value_if_true, value_if_false)

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

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
  • condition_id (str) – A reference to a condition in the Conditions section. Use the condition’s name to reference it.

  • value_if_true (Any) – A value to be returned if the specified condition evaluates to true.

  • value_if_false (Any) – A value to be returned if the specified condition evaluates to false.

Return type

ICfnConditionExpression

Returns

an FnCondition token

classmethod condition_not(condition)

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.

Parameters

condition (ICfnConditionExpression) – A condition such as Fn::Equals that evaluates to true or false.

Return type

ICfnConditionExpression

Returns

an FnCondition token

classmethod condition_or(*conditions)

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.

Parameters

conditions (ICfnConditionExpression) – conditions that evaluates to true or false.

Return type

ICfnConditionExpression

Returns

an FnCondition token

classmethod find_in_map(map_name, top_level_key, second_level_key)

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

Parameters
  • map_name (str) –

  • top_level_key (str) –

  • second_level_key (str) –

Return type

str

Returns

a token represented as a string

classmethod get_att(logical_name_of_resource, attribute_name)

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

Parameters
  • logical_name_of_resource (str) – The logical name (also called logical ID) of the resource that contains the attribute that you want.

  • attribute_name (str) – The name of the resource-specific attribute whose value you want. See the resource’s reference page for details about the attributes available for that resource type.

Return type

IResolvable

Returns

an IResolvable object

classmethod get_azs(region=None)

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

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

region (Optional[str]) – The name of the region for which you want to get the Availability Zones. You can use the AWS::Region pseudo parameter to specify the region in which the stack is created. Specifying an empty string is equivalent to specifying AWS::Region.

Return type

List[str]

Returns

a token represented as a string array

classmethod import_list_value(shared_value_to_import, assumed_length, delimiter=None)

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

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.

Parameters
  • shared_value_to_import (str) –

  • assumed_length (Union[int, float]) –

  • delimiter (Optional[str]) –

Return type

List[str]

classmethod import_value(shared_value_to_import)

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.

Parameters

shared_value_to_import (str) – The stack output value that you want to import.

Return type

str

Returns

a token represented as a string

classmethod join(delimiter, list_of_values)

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.

Parameters
  • delimiter (str) – The value you want to occur between fragments. The delimiter will occur between fragments only. It will not terminate the final value.

  • list_of_values (Sequence[str]) – The list of values you want combined.

Return type

str

Returns

a token represented as a string

classmethod parse_domain_name(url)

Given an url, parse the domain name.

Parameters

url (str) – the url to parse.

Return type

str

classmethod ref(logical_name)

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

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

Parameters

logical_name (str) – The logical name of a parameter/resource for which you want to retrieve its value.

Return type

str

classmethod ref_all(parameter_type)

Returns all values for a specified parameter type.

Parameters

parameter_type (str) – An AWS-specific parameter type, such as AWS::EC2::SecurityGroup::Id or AWS::EC2::VPC::Id. For more information, see Parameters in the AWS CloudFormation User Guide.

Return type

List[str]

Returns

a token represented as a string array

classmethod select(index, array)

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

Parameters
  • index (Union[int, float]) – The index of the object to retrieve. This must be a value from zero to N-1, where N represents the number of elements in the array.

  • array (Sequence[str]) – The list of objects to select from. This list must not be null, nor can it have null entries.

Return type

str

Returns

a token represented as a string

classmethod split(delimiter, source, assumed_length=None)

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

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
  • delimiter (str) – A string value that determines where the source string is divided.

  • source (str) – The string value that you want to split.

  • assumed_length (Union[int, float, None]) – The length of the list that will be produced by splitting.

Return type

List[str]

Returns

a token represented as a string array

classmethod sub(body, variables=None)

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.

Parameters
  • body (str) – A string with variables that AWS CloudFormation substitutes with their associated values at runtime. Write variables as ${MyVarName}. Variables can be template parameter names, resource logical IDs, resource attributes, or a variable in a key-value map. If you specify only template parameter names, resource logical IDs, and resource attributes, don’t specify a key-value map.

  • variables (Optional[Mapping[str, str]]) – The name of a variable that you included in the String parameter. The value that AWS CloudFormation substitutes for the associated variable name at runtime.

Return type

str

Returns

a token represented as a string

classmethod transform(macro_name, parameters)

Creates a token representing the Fn::Transform expression.

Parameters
  • macro_name (str) – The name of the macro to perform the processing.

  • parameters (Mapping[str, Any]) – The parameters to be passed to the macro.

Return type

IResolvable

Returns

a token representing the transform expression

See

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

classmethod value_of(parameter_or_logical_id, attribute)

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

Parameters
  • parameter_or_logical_id (str) – The name of a parameter for which you want to retrieve attribute values. The parameter must be declared in the Parameters section of the template.

  • attribute (str) – The name of an attribute from which you want to retrieve a value.

Return type

str

Returns

a token represented as a string

classmethod value_of_all(parameter_type, attribute)

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

Parameters
  • parameter_type (str) – An AWS-specific parameter type, such as AWS::EC2::SecurityGroup::Id or AWS::EC2::VPC::Id. For more information, see Parameters in the AWS CloudFormation User Guide.

  • attribute (str) – The name of an attribute from which you want to retrieve a value. For more information about attributes, see Supported Attributes.

Return type

List[str]

Returns

a token represented as a string array