pub struct Stack { /* private fields */ }Expand description
Represents a CloudFormation stack containing AWS resources and their configurations.
A Stack is the core abstraction for defining and managing AWS infrastructure.
It contains a collection of AWS resources (such as Lambda functions, S3 buckets, DynamoDB tables, etc.)
that are deployed together as a single unit in AWS CloudFormation.
§Usage
Stacks are created using the StackBuilder, which provides a fluent interface for adding resources.
Once built, a stack can be:
- Synthesized into a CloudFormation template JSON using
synth() - Deployed to AWS using the deployment utilities (
deploy)
§Example
use rusty_cdk_core::stack::StackBuilder;
use rusty_cdk_core::sqs::QueueBuilder;
let mut stack_builder = StackBuilder::new();
// Add resources to the stack
QueueBuilder::new("my-queue")
.standard_queue()
.build(&mut stack_builder);
// Build the stack
let stack = stack_builder.build().unwrap();
// Synthesize to CloudFormation template
let template_json = stack.synth().unwrap();§Serialization
The stack is serialized to CloudFormation-compatible JSON format, with:
Resources: The AWS resources mapMetadata: Additional metadata for resource management- Tags are not serialized directly
Implementations§
Source§impl Stack
impl Stack
pub fn get_assets(&self) -> Vec<Asset>
Sourcepub fn synth(&self) -> Result<String, String>
pub fn synth(&self) -> Result<String, String>
Synthesizes the stack into a new CloudFormation template JSON string.
This method converts the stack and all its resources into a JSON-formatted CloudFormation template that can be deployed to AWS using the AWS CLI, SDKs, or the AWS Console.
This method always created a ‘fresh’ template, and its ids might not match those of an earlier synthesis.
Use synth_for_existing if you want to keep the existing resource ids.
The deployment methods of this library (deploy and deploy_with_result) automatically check the resource ids when updating a stack.
§Returns
Ok(String)- A JSON-formatted CloudFormation template stringErr(String)- An error message if serialization fails
§Example
use rusty_cdk_core::stack::StackBuilder;
use rusty_cdk_core::sqs::QueueBuilder;
let mut stack_builder = StackBuilder::new();
// Add resources to the stack
QueueBuilder::new("my-queue")
.standard_queue()
.build(&mut stack_builder);
// Build the stack
let stack = stack_builder.build().unwrap();
// Synthesize to a 'fresh' CloudFormation template
let template_json = stack.synth().unwrap();§Usage with AWS Tools
The synthesized template can be used with:
- AWS CLI:
aws cloudformation create-stack --template-body file://template.json - AWS SDKs: Pass the template string to the CloudFormation client
- AWS Console: Upload the template file directly
Sourcepub fn synth_for_existing(
&mut self,
existing_stack: &str,
) -> Result<String, String>
pub fn synth_for_existing( &mut self, existing_stack: &str, ) -> Result<String, String>
Synthesizes the stack into a CloudFormation template JSON string.
This method converts the stack and all its resources into a JSON-formatted CloudFormation template that can be deployed to AWS using the AWS CLI, SDKs, or the AWS Console.
It makes sure the resource ids match those of an existing stack. This will only work if the existing stack was also created with this library.
§Parameters
existing_stack- The existing stack, as a CloudFormation template JSON string
§Returns
Ok(String)- A JSON-formatted CloudFormation template stringErr(String)- An error message if serialization fails
§Example
use rusty_cdk_core::stack::StackBuilder;
use rusty_cdk_core::sqs::QueueBuilder;
let mut stack_builder = StackBuilder::new();
// Add resources to the stack
QueueBuilder::new("my-queue")
.standard_queue()
.build(&mut stack_builder);
// Build the stack
let mut stack = stack_builder.build().unwrap();
// Retrieve the existing stack template
let existing_stack_template = r#"{"Resources": { "LogGroup198814893": { "Type": "AWS::Logs::LogGroup", "Properties": { "RetentionInDays": 731 } } }, "Metadata": { "myFunLogGroup": "LogGroup198814893" } }"#;
// Synthesize to a CloudFormation template respecting the existing ids
let template_json = stack.synth_for_existing(existing_stack_template).unwrap();§Usage with AWS Tools
The synthesized template can be used with:
- AWS CLI:
aws cloudformation create-stack --template-body file://template.json - AWS SDKs: Pass the template string to the CloudFormation client
- AWS Console: Upload the template file directly
pub fn get_diff(&self, existing_stack: &str) -> Result<StackDiff, String>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Stack
impl<'de> Deserialize<'de> for Stack
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Stack, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Stack, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Stack
impl Serialize for Stack
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for Stack
impl RefUnwindSafe for Stack
impl Send for Stack
impl Sync for Stack
impl Unpin for Stack
impl UnsafeUnpin for Stack
impl UnwindSafe for Stack
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more