The ‘alfred’ helper and the CloudFormation parameter files - AWS Control Tower

The ‘alfred’ helper and the CloudFormation parameter files

CfCT provides you with a mechanism known as the alfred helper to get the value for an SSM Parameter Store key that's defined in the CloudFormation template. Using the alfred helper, you can use values that are stored in the SSM Parameter Store and without updating the CloudFormation template. For more information, see What is an CloudFormation template? in the CloudFormation User Guide.

Important

The alfred helper has two limitations. Parameters are available only in the home region of the AWS Control Tower management account. As a best practice, consider working with values that don't change from stack instance to stack instance. When the 'alfred' helper retreives parameters, it chooses a random stack instance from the stack set that exports the variable.

Example

Suppose that you have two CloudFormation stack sets. Stack set 1 has one stack instance and deploys to one account in one Region. It creates an Amazon VPC and subnets in an availability zone, and the VPC ID and subnet ID must be passed into stack set 2 as parameter values. Before the VPC ID and subnet ID can be passed to stack set 2, the VPC ID and subnet ID must be stored in stack set 1 using AWS:::SSM::Parameter. For more information, see AWS:::SSM::Parameter in the CloudFormation User Guide.

CloudFormation stack set 1:

In the following snippet, the alfred helper can gets value for the VPC ID and subnet ID from the parameter store and pass them as input to the StackSet state machine.

VpcIdParameter: Type: AWS::SSM::Parameter Properties: Name: '/stack_1/vpc/id' Description: Contains the VPC id Type: String Value: !Ref MyVpc SubnetIdParameter: Type: AWS::SSM::Parameter Properties: Name: '/stack_1/subnet/id' Description: Contains the subnet id Type: String Value: !Ref MySubnet

CloudFormation stack set 2:

The snippet shows the parameters that are specified in the CloudFormation stack 2 manifest.yaml file.

parameters: - parameter_key: VpcId parameter_value: $[alfred_ssm_/stack_1/vpc/id] - parameter_key: SubnetId parameter_value: $[alfred_ssm_/stack_1/subnet/id]

CloudFormation stack set 2.1:

The snippet shows that you can list alfred_ssm properties to support parameters of type CommaDelimitedList. For more information, see Parameters in the CloudFormation User Guide.

parameters: - parameter_key: VpcId # Type: String parameter_value: $[alfred_ssm_/stack_1/vpc/id'] - parameter_key: SubnetId # Type: String parameter_value: $[ alfred_ssm_/stack_1/subnet/id'] - parameter_key: AvailablityZones # Type: CommaDelimitedList parameter_value:
 - "$[alfred_ssm_/availability_zone_1]"
 - "$[alfred_ssm_/availability_zone_2]"