Generate CloudFormation templates from existing resources and infrastructure for reverse engineering and automation scenarios. The Generated Templates feature allows you to create templates from existing AWS resources that weren't originally managed by CloudFormation.
Creates a new generated template from existing AWS resources.
/**
* Creates a template from existing resources that are not already managed with CloudFormation
* You can check status using DescribeGeneratedTemplate
*/
class CreateGeneratedTemplateCommand {
constructor(input: CreateGeneratedTemplateCommandInput);
}
interface CreateGeneratedTemplateCommandInput {
/** Name for the generated template (unique within region) */
GeneratedTemplateName: string;
/** List of existing AWS resources to include in the template */
Resources?: ResourceDefinition[];
/** Stack name if generating from an existing stack */
StackName?: string;
/** Template configuration options */
TemplateConfiguration?: TemplateConfiguration;
}
interface CreateGeneratedTemplateCommandOutput {
/** Unique identifier for the generated template */
GeneratedTemplateId?: string;
}
interface ResourceDefinition {
/** AWS resource type (e.g., AWS::S3::Bucket) */
ResourceType: string;
/** Logical resource identifier in the template */
LogicalResourceId?: string;
/** Properties to identify the existing resource */
ResourceIdentifier: ResourceIdentifierProperties;
}
interface ResourceIdentifierProperties {
[key: string]: string;
}
interface TemplateConfiguration {
/** Default deletion policy for resources */
DeletionPolicy?: "DELETE" | "RETAIN";
/** Default update replace policy for resources */
UpdateReplacePolicy?: "DELETE" | "RETAIN";
}Usage Example:
import { CloudFormationClient, CreateGeneratedTemplateCommand } from "@aws-sdk/client-cloudformation";
const client = new CloudFormationClient({ region: "us-east-1" });
const command = new CreateGeneratedTemplateCommand({
GeneratedTemplateName: "my-reverse-engineered-template",
Resources: [
{
ResourceType: "AWS::S3::Bucket",
LogicalResourceId: "MyExistingBucket",
ResourceIdentifier: {
BucketName: "my-existing-bucket-name"
}
},
{
ResourceType: "AWS::EC2::Instance",
LogicalResourceId: "MyExistingInstance",
ResourceIdentifier: {
InstanceId: "i-1234567890abcdef0"
}
}
],
TemplateConfiguration: {
DeletionPolicy: "RETAIN",
UpdateReplacePolicy: "RETAIN"
}
});
const response = await client.send(command);
console.log("Generated template ID:", response.GeneratedTemplateId);Retrieves the contents and status of a generated template.
/**
* Retrieves information about a generated template including its contents
* and current generation status
*/
class GetGeneratedTemplateCommand {
constructor(input: GetGeneratedTemplateCommandInput);
}
interface GetGeneratedTemplateCommandInput {
/** Name or ID of the generated template */
GeneratedTemplateName?: string;
/** Format for the template output */
Format?: TemplateFormat;
}
interface GetGeneratedTemplateCommandOutput {
/** Current status of template generation */
Status?: GeneratedTemplateStatus;
/** Generated CloudFormation template content */
TemplateBody?: string;
/** Reason for the current status */
StatusReason?: string;
/** Creation timestamp */
CreationTime?: Date;
/** Last update timestamp */
LastUpdatedTime?: Date;
/** Progress information */
Progress?: TemplateProgress;
}
type GeneratedTemplateStatus =
| "CreatePending"
| "UpdatePending"
| "DeletePending"
| "CreateInProgress"
| "UpdateInProgress"
| "DeleteInProgress"
| "Failed"
| "Complete";
type TemplateFormat = "JSON" | "YAML";
interface TemplateProgress {
/** Number of resources successfully processed */
ResourcesSucceeded?: number;
/** Number of resources that failed processing */
ResourcesFailed?: number;
/** Number of resources currently being processed */
ResourcesProcessing?: number;
/** Number of resources pending processing */
ResourcesPending?: number;
}Updates an existing generated template with new resources or configuration.
/**
* Updates a generated template by adding, removing, or modifying resources
*/
class UpdateGeneratedTemplateCommand {
constructor(input: UpdateGeneratedTemplateCommandInput);
}
interface UpdateGeneratedTemplateCommandInput {
/** Name of the generated template to update */
GeneratedTemplateName: string;
/** New name for the template (optional) */
NewGeneratedTemplateName?: string;
/** Resources to add to the template */
AddResources?: ResourceDefinition[];
/** Logical IDs of resources to remove */
RemoveResources?: string[];
/** Updated template configuration */
TemplateConfiguration?: TemplateConfiguration;
}
interface UpdateGeneratedTemplateCommandOutput {
/** Updated template ID */
GeneratedTemplateId?: string;
}Retrieves metadata and status information about a generated template.
/**
* Describes a generated template's metadata and current status
*/
class DescribeGeneratedTemplateCommand {
constructor(input: DescribeGeneratedTemplateCommandInput);
}
interface DescribeGeneratedTemplateCommandInput {
/** Name of the generated template */
GeneratedTemplateName: string;
}
interface DescribeGeneratedTemplateCommandOutput {
/** Template ID */
GeneratedTemplateId?: string;
/** Template name */
GeneratedTemplateName?: string;
/** List of resources included in the template */
Resources?: ResourceDetail[];
/** Current status */
Status?: GeneratedTemplateStatus;
/** Status reason */
StatusReason?: string;
/** Creation timestamp */
CreationTime?: Date;
/** Last updated timestamp */
LastUpdatedTime?: Date;
/** Progress information */
Progress?: TemplateProgress;
/** Total number of resources */
TotalWarnings?: number;
}
interface ResourceDetail {
/** Resource type */
ResourceType?: string;
/** Logical resource ID */
LogicalResourceId?: string;
/** Resource identifier properties */
ResourceIdentifier?: ResourceIdentifierProperties;
/** Current processing status */
ResourceStatus?: ResourceStatus;
/** Status reason */
ResourceStatusReason?: string;
/** Warnings about the resource */
Warnings?: WarningDetail[];
}
type ResourceStatus =
| "Pending"
| "InProgress"
| "Failed"
| "Complete";
interface WarningDetail {
/** Warning type */
Type?: WarningType;
/** Warning properties */
Properties?: WarningProperty[];
}
type WarningType =
| "MUTUALLY_EXCLUSIVE_PROPERTIES"
| "UNSUPPORTED_PROPERTIES"
| "MUTUALLY_EXCLUSIVE_TYPES";
interface WarningProperty {
/** Property path */
PropertyPath?: string;
/** Required properties */
Required?: boolean;
/** Property description */
Description?: string;
}Deletes a generated template and its associated data.
/**
* Deletes a generated template
*/
class DeleteGeneratedTemplateCommand {
constructor(input: DeleteGeneratedTemplateCommandInput);
}
interface DeleteGeneratedTemplateCommandInput {
/** Name of the generated template to delete */
GeneratedTemplateName: string;
}
interface DeleteGeneratedTemplateCommandOutput {}Lists all generated templates in the current region.
/**
* Returns a list of generated templates
*/
class ListGeneratedTemplatesCommand {
constructor(input: ListGeneratedTemplatesCommandInput);
}
interface ListGeneratedTemplatesCommandInput {
/** Pagination token for subsequent requests */
NextToken?: string;
/** Maximum number of results to return */
MaxResults?: number;
}
interface ListGeneratedTemplatesCommandOutput {
/** List of generated template summaries */
Summaries?: GeneratedTemplateSummary[];
/** Pagination token for next page */
NextToken?: string;
}
interface GeneratedTemplateSummary {
/** Template ID */
GeneratedTemplateId?: string;
/** Template name */
GeneratedTemplateName?: string;
/** Current status */
Status?: GeneratedTemplateStatus;
/** Status reason */
StatusReason?: string;
/** Creation timestamp */
CreationTime?: Date;
/** Last updated timestamp */
LastUpdatedTime?: Date;
/** Number of resources */
NumberOfResources?: number;
}Usage Example:
import {
CloudFormationClient,
GetGeneratedTemplateCommand,
DescribeGeneratedTemplateCommand
} from "@aws-sdk/client-cloudformation";
const client = new CloudFormationClient({ region: "us-east-1" });
// Check generation status
const statusCommand = new DescribeGeneratedTemplateCommand({
GeneratedTemplateName: "my-reverse-engineered-template"
});
const statusResponse = await client.send(statusCommand);
if (statusResponse.Status === "Complete") {
// Get the generated template
const getCommand = new GetGeneratedTemplateCommand({
GeneratedTemplateName: "my-reverse-engineered-template",
Format: "YAML"
});
const templateResponse = await client.send(getCommand);
console.log("Generated template:", templateResponse.TemplateBody);
}