26 votes

How to upload a file into S3 bucket using CloudFormation script?

AWS provides a sample Macro that may help, depending on your use case: https://github.com/awslabs/aws-cloudformation-templates/tree/a11722d/aws/services/CloudFormation/MacrosExamples/S3Objects. ...
Alan Ivey's user avatar
  • 1,761
19 votes

AWS CloudFormation - Custom variables in templates

I don't have an answer, but did want to point out that you can save yourself a lot of pain by using Fn::Sub in place of Fn::Join { "Fn::Sub": "${ELBHostName"}-1.${EnvironmentVersioned}.${HostedZone}"}...
Kevin Audleman's user avatar
17 votes
Accepted

Cloudformation fails with "AMI cannot be described"

The AMI was deleted by another user at the same time I did my edits. The message "AMI cannot be described" actually means "AMI could not be found". Hope this helps someone.
user2707671's user avatar
16 votes
Accepted

Can FindInMap return a list?

Using the Split function works: JSON "Mappings": { "AWSEnv2PublicSubnets": { "DEV": { "subList": "subnet-1111,subnet-2222,subnet-3333" } } } then: "Subnets" : { ...
gregmac's user avatar
  • 1,599
14 votes
Accepted

Is it possible to force Re-creation of EC2::Instance or RDS::DBInstance in amazon cloudformation?

For instance store-backed EC2 instances, one trick is to add a comment to the user data script containing a version number, date, or similar, then change that whenever you want the instance recreated: ...
markusk's user avatar
  • 485
14 votes

Cloudformation can I create a new role referencing an existing policy?

src: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html The AWS::IAM::Role types now have a ManagedPolicyArns field where you can set this. You just need to ...
John Eikenberry's user avatar
12 votes

Referring to an existing resource in CF Template

I recently had to do this for some layered deployments which referenced shared services. In addition to parameters, here are some other options: Named exports: this is a good option if you have some ...
Chris Adams's user avatar
12 votes
Accepted

Can't SSH into AWS CloudFormation Stack Instance

The problem is that the CloudFormation template creates a RouteTable with the default route 0.0.0.0/0 correctly pointing to the IGW, however you don't associate the RouteTable with your subnets. What ...
MLu's user avatar
  • 24.9k
11 votes

How do I get AWS CloudFormation to recreate a resource I manually deleted?

The easiest way is to give the EC2 instance a different resource name and update the stack. Cloudformation will interpret that as you creating an entirely new instance and create it. Another ...
Peter Dolberg's user avatar
11 votes

Can FindInMap return a list?

I think Mappings value supports List type (at least as of now). https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html The Mappings section consists of the ...
onelaview's user avatar
  • 211
10 votes

How to retrieve AWS SNS Arn value

In your CloudFormation template, if you simply reference your SNS topic, then you'll get the ARN. For example: { "Ref": "MySnsTopic" } So you can use that as input to your nested CloudFormation ...
Matt Houser's user avatar
  • 10.1k
9 votes

Amazon CloudFormation: How to get an ELB's private IP for a specific subnet?

If you want to get the private ip address of an elb, check network interfaces under network and security in you ec2 dashboard.
JasdeepSingh's user avatar
9 votes

How to specify VPC and subnet in AWS CloudFormation template

If you want to continue using default VPC you deleted you will have to contact AWS support to create it again. AWS resources from the template you are using depnd on it. Otherwise you have to ...
dsmsk80's user avatar
  • 5,837
8 votes

Specifying a VPC in a CloudFormation template for an EC2 instance

For EC2 Instances, you get to skip specifying the VPC ID and instead, just specify the subnet you want the instance in. From there, the VPC is assumed. Inside of your "Properties" array, add the ...
EEAA's user avatar
  • 109k
8 votes

specify root volume size for ec2 instance in cloudformation

I had been stuck for days to change root-disk size using Cloudformation, , this is how it works for me.. If you use /dev/xvda1 the instance will fail, the correct way is to use /dev/xvda. Using YAML ...
Ahmad Hassaan's user avatar
8 votes
Accepted

how to pull docker image on ECR using cloudformation template

Using ECR, EC2 and docker, you are still required to do a docker login. In the user data run aws ecr get-login --no-include-email > login.sh bash login.sh then you should be able to run ...
strongjz's user avatar
  • 842
7 votes
Accepted

AWS CloudFormation - Custom variables in templates

I was looking of the same functionality. Using a nested stack as SpoonMeiser suggested came to mind, but then I realised that what I actually needed was custom functions. Luckily CloudFormation allows ...
Claude's user avatar
  • 196
7 votes

Amazon CloudFormation: How to get an ELB's private IP for a specific subnet?

JQ parsing version, just FYI. aws ec2 describe-network-interfaces --filters "Name=description,Values=ELB your-elb-name" --output json | jq ".NetworkInterfaces[].PrivateIpAddresses[].PrivateIpAddress"
BlackPioter's user avatar
6 votes

How do I associate an ssh key pair with the instance created by a stack in Amazon CloudFormation?

AWS CloudFormation parameters can also give you a list of all key's that are available in your account & region. Just change the "Type" of the parameter to the desired AWS type. That will be "AWS::...
Frank Zomerdijk's user avatar
6 votes

AWS Cloudformation - can't add multiple subnet associations to a public routing table

As @Marcus explained in his response to his own question; it is the lack of the DependsOn attribute when you create an AWS::EC2::Route entry where you specify a Gateway. For route entries that ...
lantrix's user avatar
  • 239
6 votes

AWS Cloud Formation.Requires capabilities : [CAPABILITY_IAM] (Child Stack)

I just ran into this issue, my problem was that I did not check the checkbox "I acknowledge that this template might cause AWS CloudFormation to create IAM resources." on the last screen before ...
AsTeR's user avatar
  • 257
6 votes

Unable to mount EBS drives to an Ubuntu box using AWS CloudFormation (UserData not working)

Here's the answer - the EBS needs to be attached fully. "UserData": { "Fn::Base64": { "Fn::Join": ["", [ ...
Michael Manoochehri's user avatar
6 votes

Passing parameters to AWS Lambda

You can pass ES cluster endpoint to Lambda function as an environment variable. Here is a snippet of CloudFormation template for such function: "mylambda": { "Type": "AWS::Lambda::Function", "...
dsmsk80's user avatar
  • 5,837
6 votes
Accepted

Configuring X-Ray in Lambda with AWS CloudFormation vs TracingConfig

While not clear, TracingConfig is the setting to enable AWS X-Ray. TracingConfig is a property of the AWS::Lambda::Function resource that configures tracing settings for your AWS Lambda (Lambda) ...
ivlo11's user avatar
  • 76
6 votes
Accepted

AWS::CloudFormation::Init not executing commands

You have to execute cfn-init in order for AWS::CloudFormation::Init to do anything. This is most commonly done via cloud-init user data. Here is the example from the cfn-init documentation: UserData: ...
jordanm's user avatar
  • 889
5 votes

Creating AWS VPC Endpoints with CloudFormation

This is what you're looking for: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpcendpoint.html AWS::EC2::VPCEndpoint The AWS::EC2::VPCEndpoint resource creates a VPC ...
Joaquin Sargiotto's user avatar
5 votes
Accepted

How to get public IP of instance in CloudFormation template when using LaunchConfig

If your UserData contains a shell script and all you need to do is reference the instance's own public IP within that script, you can get this value by querying the public-ipv4 category of the ...
Will Jordan's user avatar
5 votes
Accepted

Cloud Formation template add ingress rule to existing security group

Yes, it can be done. You need to pass the security group identifier (for Security Group A) into the template for Template B as a parameter. From there, you can reference Security Group A in a AWS::...
Matt Houser's user avatar
  • 10.1k
5 votes
Accepted

CloudFormation stack yaml syntax?

You have an extra '-' character in the Tags definition. It should look something like the snippet below (I'm not sure of the Join syntax, personally I use Sub normally): Tags: - Key: Name ...
David Hutchison's user avatar
5 votes
Accepted

CloudFormation template: how to use Sub and GetAtt at the same time in short form?

Simply remove !GetAtt and reference the desired variable. In the following code EIP.AllocationId normally returned via !GetAtt. !Sub | #!/bin/bash export INSTANCEID=$(curl -s http://169.254.169....
spinnerdog's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible