====== AWS Cloud Formation ====== ===== Code Examples ===== [[aws:aws-deploy_cloudformation_from_cli|Deploy CloudFormation from cli]] \\ [[aws:aws-cloudformation_refs|Using !Ref]] \\ [[aws:aws-cloudformation-parameters-mappings-refs|Parameters, Mappings, and !Refs]] \\ [[aws:aws-cloudformation_mappings_outputs|Cloud Formation Mappings and Output Section]] \\ [[aws:aws-cloudformation_big_example|Example from course for best practice example]] \\ [[aws:lambda#cloud_formation_version_in_yaml|AWS Lambda Function with Tags]] ===== Set numeric value to string ===== Force an string value instead of integer (join two strings with nothing, ""):- !Join ["", ["00", "1002899"]] ===== Tags ===== Properties: Tags: - Key: "Tag1" Value: "TagValue" - Key: "CreatedBy" Value: "CloudFormation" ===== Outputs and Exports ===== From:- [[https://aws.amazon.com/blogs/aws/aws-cloudformation-update-yaml-cross-stack-references-simplified-substitution/]] You can now create and export values from one stack and make use of them in other stacks without going to the trouble of creating custom CloudFormation resources. The first stack exports values like this: Outputs: TSSG: Value: !Ref TroubleShootingSG Export: Name: AccountSG The other stacks then reference them using the new ImportValue function: EC2Instance: Type: AWS::EC2::Instance Properties: SecurityGroups: - !ImportValue AccountSG ===== StackSet - CLI ===== ==== Create StackSet ==== aws cloudformation create-stack-set --stack-set-name --description "Description Text" --template-body file://template.yaml --profile profile1234 --capabilities CAPABILITY-WHATEVER --parameters file://parameters.json --auto-deployment file://auto-deployment.json --managed-execution Active=false --auto-deployment Enabled=true, RetainStacksOnAccountRemoval=false autodeployment.json { "Enabled": true, "RetainStacksOnAccountRemoval": false } ==== Deploy Stackset ==== aws cloudformation create-stack-instances --stack-set-name "Name" --accounts 123412341234 --regions file://regions.json --output json --profile profile1234 regions.json:- ["eu-west-1", "us-east-1"]