Export AWS configuration as CloudFormation template - amazon-web-services

I´m using AWS CLI and CloudFormation, and I could not find any reference in the documentation.
Does anybody know if it´s possible to create a CloudFormation template from a current configuration.
Let´s say that I want to get a CloudFormation template from my current security group configuration.
Any idea if it´s possible to export that configuration as a template using CLI?

Based on our experience we found 3 possible ways to translate existing manually deployed (from Web Console UI) AWS infra to Cloudformation (CF).
Using a new CloudFormation native introduced feature (since Nov 2019) that allows you to Import existing resources into a CloudFormation stack
Using aws cli execute $aws service_name_here describe for each element that make up your stack eg for RDS Database Stack:
RDS Instance -> Type: AWS::RDS::DBInstance,
RDS (EC2) SG -> Type: AWS::EC2::SecurityGroup,
RDS Subnet Group -> Type: AWS::RDS::DBSubnetGroup and
RDS DB Param Group -> Type: AWS::RDS::DBParameterGroup
And manually translate to CF based on the outputs obtained from the aws cli for each of the components. This approach usually requires more experience in both AWS and CF but the templates that you are creating can be structured and designed under good practices, fully parameterized (Sub, Ref, Join, Fn::GetAtt:, Fn::ImportValue), modular, applying conditions and in a 1st iteration the result would probably be close to the final state of the templates (interesting reference examples: https://github.com/widdix/aws-cf-templates/).
Extra points! :)
Some other new alternatives to export your current deployed AWS infra to Cloudformation / Terraform code:
https://former2.com
https://modules.tf
https://www.brainboard.co/
Related Article: https://medium.com/#exequiel.barrirero/aws-export-configuration-as-code-cloudformation-terraform-b1bca8949bca

It's not possible using the AWS CLI but you can use the CloudFormer [1] tool to create a CloudFormation template from existing resources. I've had decent success with it. The templates aren't as "pretty" as hand-made templates but they provide a good starting point.
[1] http://aws.amazon.com/developertools/6460180344805680

In addition to CloudFormer, you might want to take a look at Bellerophon: https://github.com/arminhammer/bellerophon.

I had some problems getting the tradidtional tools - mentioned above - working in our environment; we have a complicated API Gateway. Former2 didnt' find it at all (although seemed ideal for other resources)
I found another tool, "Terraformer" which extracts AWS into Terraform, which can then be turned into CloudFormation -or used directly as IaC.
https://github.com/GoogleCloudPlatform/terraformer#installation
Maybe that will work for others if the above tools don't.

Related

Can we export Cloud Formation template from an existing VPC?

We have a VPC which contains all services and databases used for the testing. We are now planning to setup another such VPC, so that we can have an extra testing env.
Is there a way to export the CloudFormation template from the existing infrastructure ( VPC )?
Depends upon what all you want to clone/duplicate as well as to what level you would like to duplicate resources, you can look at following options;
Use deprecated CloudFomer which is part of AWS CFN, you can built templates from your existing resources. Not recommended, just putting in list in case your use-cases are meet with this with less efforts, time and money.
Use former2 a third party tool, which is more reliable than CloudFomer. Please refer this existing thread for more details.
Use N2WS, a third party partnered solution with AWS. Please refer this Blog from AWS.
Use CloudRanger, third party solution knows as Druva.
If the existing infrastructure were created using CloudFormation then you can just run the following command:
aws cloudformation get-template --stack-name myteststack
If not it's not possible because aws only uses cloudformation stacks visible for clients in products than you can change parameters after creation, like ECS.
You can export Cloud Formation template using Functionbeat which is Elastic Beat that we can deploy as a function in our serverless environment to collect data from cloud services. After configuring functionbeat use the following command to export the CloudFormation template.
For Linux and Mac ./functionbeat export function FUNCTION_NAME
For Windows .\functionbeat.exe export function FUNCTION_NAME
Functionbeat will write the CloudFormation template to standard output or stdout which you can modify if needed.

Cloudformation template from existing resources or other possibilities to replicate environment

I have created an ec2 instance and configured it as a target behind my load balancer. I want to convert this entire environment as something that can be deployed repeatedly in automation. I have looked at cloudformation but don't know if it can help me with converting this environment to a cloudformation template. Is there any other way to achieve this. If there is an approach outside of Cloudformation, that's fine too.
PS: I am new to AWS and it's capabilities
Thanks
Have a look at Former2.
Former2 allows you to generate Infrastructure-as-Code outputs from your existing resources within your AWS account.
You need an IaC (Infrastructure as Code) tool. Cloudformation is one of them, but there are plenty others. Terraform, Pulumi or even the AWS CDK.
Look at Infrastructure as Code try AWS CDK, Terraform, you should also look at methods for replacing existing infrastructure. Spinning a fresh set of infrastructure along side the existing one and swapping out in DNS is the most common of approach.

AWS CloudFormation template generation issue

I have AWS Lambda service running which I had developed and deployed using the AWS SAM CLI. There are some other services as like ElasticCache, RDS, etc running in my AWS Account.
Now my requirement is to generate the CloudFormation YAML template file out of existing running service which I can use to provision later and keep as a backup. For this, I used CloudFormer template however problem is that CloudFormer does not consider or generate YAML template for AWS Lambda services which I had noticed. And also I believe CloudFormer has become obsolete as well.
Please assist me here to let me know if there any latest service from AWS that can fulfil my requirement here.
Thank you
CloudFormation supports the creation of stacks from existing resources.
Take a further look: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resource-import-new-stack.html
Unfortunately, there is no such functionality, apart from CloudFormer which is not maintained anymore by AWS nor reliable (in beta for years).
To use the importing resources feature into CFN, you have to manually write its template. This means you prepare your templates for RDS or EC, which match exactly your existing resources. If you have written the yaml or json template for the imported resources, you then can attempt to import them. In other words, the feature does not generate yaml code for you.
Maybe there are some non-AWS third party tools for that, but I'm not aware of any worth recommending unfortunately.
There is an opensource replacement for Cloudformer named former2 at https://github.com/iann0036/former2. I believe it can work as both a chrome/firefox addon and a cli tool.

CloudFormation Template for ElasticTranscoder

As part of infra automation we are using cloudformation for automating the AWS infrastructure. We are utilising the service ElaticTranscoder as well, as i understand cloudformation yet does not provide support for ElasticTranscoder, is there any efficient way to automate ElasticTranscoder using cloudformation.
Custom resources provide a way for you to write custom provisioning logic in AWS CloudFormation template and have AWS CloudFormation run it during a stack operation, such as when you create, update or delete a stack.
Check out this example.
Also, a quick google search gives me this result.
Another option is not using CloudFormation. You can use Terraform which does support Elastic Transcoder.
https://www.terraform.io/docs/providers/aws/r/elastic_transcoder_pipeline.html
Ansible also has third-party support for it.
https://github.com/wimnat/ansible-modules/blob/master/elastictranscoder/elastictranscoder.py
Last but not least, you can vote for this feature in AWS wish list by liking or retweeting the request.
https://twitter.com/search?q=%23awswishlist%20transcoder&src=typd
https://awswishlist.com/

Cloudformation : is it possible to export current aws configuration as template?

I just created Dynamodb table, Lambda function, S3 bucket, etc. I would like to know if there's a way to export this configuration as cloudformation template
CloudFormer is designed to accomplish this, but it does not support Lambda functions, API Gateway and other services. Also, it is clunky, requires spinning up an EC2 instance and is not designed to create reusable templates - you'll have to adapt them significantly. To my knowledge there is not a service (Amazon or otherwise) to automatically export your resources accurately. It is on the Cloudcraft roadmap, but not available yet.
Yes you could use cloudformer to export your aws resources into cloudformation template. Please refer this for example and sample steps . http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-using-cloudformer.html