AWS CloudFormation

2024/05/22 - AWS CloudFormation - 2 updated api methods

Changes  Added DeletionMode FORCE_DELETE_STACK for deleting a stack that is stuck in DELETE_FAILED state due to resource deletion failure.

DeleteStack (updated) Link ¶
Changes (request)
{'DeletionMode': 'STANDARD | FORCE_DELETE_STACK'}

Deletes a specified stack. Once the call completes successfully, stack deletion starts. Deleted stacks don't show up in the DescribeStacks operation if the deletion has been completed successfully.

See also: AWS API Documentation

Request Syntax

client.delete_stack(
    StackName='string',
    RetainResources=[
        'string',
    ],
    RoleARN='string',
    ClientRequestToken='string',
    DeletionMode='STANDARD'|'FORCE_DELETE_STACK'
)
type StackName

string

param StackName

[REQUIRED]

The name or the unique stack ID that's associated with the stack.

type RetainResources

list

param RetainResources

For stacks in the DELETE_FAILED state, a list of resource logical IDs that are associated with the resources you want to retain. During deletion, CloudFormation deletes the stack but doesn't delete the retained resources.

Retaining resources is useful when you can't delete a resource, such as a non-empty S3 bucket, but you want to delete the stack.

  • (string) --

type RoleARN

string

param RoleARN

The Amazon Resource Name (ARN) of an Identity and Access Management (IAM) role that CloudFormation assumes to delete the stack. CloudFormation uses the role's credentials to make calls on your behalf.

If you don't specify a value, CloudFormation uses the role that was previously associated with the stack. If no role is available, CloudFormation uses a temporary session that's generated from your user credentials.

type ClientRequestToken

string

param ClientRequestToken

A unique identifier for this DeleteStack request. Specify this token if you plan to retry requests so that CloudFormation knows that you're not attempting to delete a stack with the same name. You might retry DeleteStack requests to ensure that CloudFormation successfully received them.

All events initiated by a given stack operation are assigned the same client request token, which you can use to track operations. For example, if you execute a CreateStack operation with the token token1 , then all the StackEvents generated by that operation will have ClientRequestToken set as token1 .

In the console, stack operations display the client request token on the Events tab. Stack operations that are initiated from the console use the token format Console-StackOperation-ID , which helps you easily identify the stack operation . For example, if you create a stack using the console, each stack event would be assigned the same token in the following format: Console-CreateStack-7f59c3cf-00d2-40c7-b2ff-e75db0987002 .

type DeletionMode

string

param DeletionMode

Specifies the deletion mode for the stack. Possible values are:

  • STANDARD - Use the standard behavior. Specifying this value is the same as not specifying this parameter.

  • FORCE_DELETE_STACK - Delete the stack if it's stuck in a DELETE_FAILED state due to resource deletion failure.

returns

None

DescribeStacks (updated) Link ¶
Changes (response)
{'Stacks': {'DeletionMode': 'STANDARD | FORCE_DELETE_STACK'}}

Returns the description for the specified stack; if no stack name was specified, then it returns the description for all the stacks created. For more information about a stack's event history, see CloudFormation stack creation events in the CloudFormation User Guide .

Note

If the stack doesn't exist, a ValidationError is returned.

See also: AWS API Documentation

Request Syntax

client.describe_stacks(
    StackName='string',
    NextToken='string'
)
type StackName

string

param StackName

Note

If you don't pass a parameter to StackName , the API returns a response that describes all resources in the account, which can impact performance. This requires ListStacks and DescribeStacks permissions.

Consider using the ListStacks API if you're not passing a parameter to StackName .

The IAM policy below can be added to IAM policies when you want to limit resource-level permissions and avoid returning a response when no parameter is sent in the request:

{ "Version": "2012-10-17", "Statement": [{ "Effect": "Deny", "Action": "cloudformation:DescribeStacks", "NotResource": "arn:aws:cloudformation:::stack//" }] }

The name or the unique stack ID that's associated with the stack, which aren't always interchangeable:

  • Running stacks: You can specify either the stack's name or its unique stack ID.

  • Deleted stacks: You must specify the unique stack ID.

Default: There is no default value.

type NextToken

string

param NextToken

A string that identifies the next page of stacks that you want to retrieve.

rtype

dict

returns

Response Syntax

{
    'Stacks': [
        {
            'StackId': 'string',
            'StackName': 'string',
            'ChangeSetId': 'string',
            'Description': 'string',
            'Parameters': [
                {
                    'ParameterKey': 'string',
                    'ParameterValue': 'string',
                    'UsePreviousValue': True|False,
                    'ResolvedValue': 'string'
                },
            ],
            'CreationTime': datetime(2015, 1, 1),
            'DeletionTime': datetime(2015, 1, 1),
            'LastUpdatedTime': datetime(2015, 1, 1),
            'RollbackConfiguration': {
                'RollbackTriggers': [
                    {
                        'Arn': 'string',
                        'Type': 'string'
                    },
                ],
                'MonitoringTimeInMinutes': 123
            },
            'StackStatus': 'CREATE_IN_PROGRESS'|'CREATE_FAILED'|'CREATE_COMPLETE'|'ROLLBACK_IN_PROGRESS'|'ROLLBACK_FAILED'|'ROLLBACK_COMPLETE'|'DELETE_IN_PROGRESS'|'DELETE_FAILED'|'DELETE_COMPLETE'|'UPDATE_IN_PROGRESS'|'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS'|'UPDATE_COMPLETE'|'UPDATE_FAILED'|'UPDATE_ROLLBACK_IN_PROGRESS'|'UPDATE_ROLLBACK_FAILED'|'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS'|'UPDATE_ROLLBACK_COMPLETE'|'REVIEW_IN_PROGRESS'|'IMPORT_IN_PROGRESS'|'IMPORT_COMPLETE'|'IMPORT_ROLLBACK_IN_PROGRESS'|'IMPORT_ROLLBACK_FAILED'|'IMPORT_ROLLBACK_COMPLETE',
            'StackStatusReason': 'string',
            'DisableRollback': True|False,
            'NotificationARNs': [
                'string',
            ],
            'TimeoutInMinutes': 123,
            'Capabilities': [
                'CAPABILITY_IAM'|'CAPABILITY_NAMED_IAM'|'CAPABILITY_AUTO_EXPAND',
            ],
            'Outputs': [
                {
                    'OutputKey': 'string',
                    'OutputValue': 'string',
                    'Description': 'string',
                    'ExportName': 'string'
                },
            ],
            'RoleARN': 'string',
            'Tags': [
                {
                    'Key': 'string',
                    'Value': 'string'
                },
            ],
            'EnableTerminationProtection': True|False,
            'ParentId': 'string',
            'RootId': 'string',
            'DriftInformation': {
                'StackDriftStatus': 'DRIFTED'|'IN_SYNC'|'UNKNOWN'|'NOT_CHECKED',
                'LastCheckTimestamp': datetime(2015, 1, 1)
            },
            'RetainExceptOnCreate': True|False,
            'DeletionMode': 'STANDARD'|'FORCE_DELETE_STACK',
            'DetailedStatus': 'CONFIGURATION_COMPLETE'|'VALIDATION_FAILED'
        },
    ],
    'NextToken': 'string'
}

Response Structure

  • (dict) --

    The output for a DescribeStacks action.

    • Stacks (list) --

      A list of stack structures.

      • (dict) --

        The Stack data type.

        • StackId (string) --

          Unique identifier of the stack.

        • StackName (string) --

          The name associated with the stack.

        • ChangeSetId (string) --

          The unique ID of the change set.

        • Description (string) --

          A user-defined description associated with the stack.

        • Parameters (list) --

          A list of Parameter structures.

          • (dict) --

            The Parameter data type.

            • ParameterKey (string) --

              The key associated with the parameter. If you don't specify a key and value for a particular parameter, CloudFormation uses the default value that's specified in your template.

            • ParameterValue (string) --

              The input value associated with the parameter.

            • UsePreviousValue (boolean) --

              During a stack update, use the existing parameter value that the stack is using for a given parameter key. If you specify true , do not specify a parameter value.

            • ResolvedValue (string) --

              Read-only. The value that corresponds to a SSM parameter key. This field is returned only for SSM parameter types in the template.

        • CreationTime (datetime) --

          The time at which the stack was created.

        • DeletionTime (datetime) --

          The time the stack was deleted.

        • LastUpdatedTime (datetime) --

          The time the stack was last updated. This field will only be returned if the stack has been updated at least once.

        • RollbackConfiguration (dict) --

          The rollback triggers for CloudFormation to monitor during stack creation and updating operations, and for the specified monitoring period afterwards.

          • RollbackTriggers (list) --

            The triggers to monitor during stack creation or update actions.

            By default, CloudFormation saves the rollback triggers specified for a stack and applies them to any subsequent update operations for the stack, unless you specify otherwise. If you do specify rollback triggers for this parameter, those triggers replace any list of triggers previously specified for the stack. This means:

            • To use the rollback triggers previously specified for this stack, if any, don't specify this parameter.

            • To specify new or updated rollback triggers, you must specify all the triggers that you want used for this stack, even triggers you've specified before (for example, when creating the stack or during a previous stack update). Any triggers that you don't include in the updated list of triggers are no longer applied to the stack.

            • To remove all currently specified triggers, specify an empty list for this parameter.

            If a specified trigger is missing, the entire stack operation fails and is rolled back.

            • (dict) --

              A rollback trigger CloudFormation monitors during creation and updating of stacks. If any of the alarms you specify goes to ALARM state during the stack operation or within the specified monitoring period afterwards, CloudFormation rolls back the entire stack operation.

              • Arn (string) --

                The Amazon Resource Name (ARN) of the rollback trigger.

                If a specified trigger is missing, the entire stack operation fails and is rolled back.

              • Type (string) --

                The resource type of the rollback trigger. Specify either AWS::CloudWatch::Alarm or AWS::CloudWatch::CompositeAlarm resource types.

          • MonitoringTimeInMinutes (integer) --

            The amount of time, in minutes, during which CloudFormation should monitor all the rollback triggers after the stack creation or update operation deploys all necessary resources.

            The default is 0 minutes.

            If you specify a monitoring period but don't specify any rollback triggers, CloudFormation still waits the specified period of time before cleaning up old resources after update operations. You can use this monitoring period to perform any manual stack validation desired, and manually cancel the stack creation or update (using CancelUpdateStack, for example) as necessary.

            If you specify 0 for this parameter, CloudFormation still monitors the specified rollback triggers during stack creation and update operations. Then, for update operations, it begins disposing of old resources immediately once the operation completes.

        • StackStatus (string) --

          Current status of the stack.

        • StackStatusReason (string) --

          Success/failure message associated with the stack status.

        • DisableRollback (boolean) --

          Boolean to enable or disable rollback on stack creation failures:

          • true : disable rollback.

          • false : enable rollback.

        • NotificationARNs (list) --

          Amazon SNS topic Amazon Resource Names (ARNs) to which stack related events are published.

          • (string) --

        • TimeoutInMinutes (integer) --

          The amount of time within which stack creation should complete.

        • Capabilities (list) --

          The capabilities allowed in the stack.

          • (string) --

        • Outputs (list) --

          A list of output structures.

          • (dict) --

            The Output data type.

            • OutputKey (string) --

              The key associated with the output.

            • OutputValue (string) --

              The value associated with the output.

            • Description (string) --

              User defined description associated with the output.

            • ExportName (string) --

              The name of the export associated with the output.

        • RoleARN (string) --

          The Amazon Resource Name (ARN) of an Identity and Access Management (IAM) role that's associated with the stack. During a stack operation, CloudFormation uses this role's credentials to make calls on your behalf.

        • Tags (list) --

          A list of Tag s that specify information about the stack.

          • (dict) --

            The Tag type enables you to specify a key-value pair that can be used to store information about an CloudFormation stack.

            • Key (string) --

              Required . A string used to identify this tag. You can specify a maximum of 128 characters for a tag key. Tags owned by Amazon Web Services (Amazon Web Services) have the reserved prefix: aws: .

            • Value (string) --

              Required . A string containing the value for this tag. You can specify a maximum of 256 characters for a tag value.

        • EnableTerminationProtection (boolean) --

          Whether termination protection is enabled for the stack.

          For nested stacks, termination protection is set on the root stack and can't be changed directly on the nested stack. For more information, see Protecting a Stack From Being Deleted in the CloudFormation User Guide .

        • ParentId (string) --

          For nested stacks--stacks created as resources for another stack--the stack ID of the direct parent of this stack. For the first level of nested stacks, the root stack is also the parent stack.

          For more information, see Working with Nested Stacks in the CloudFormation User Guide .

        • RootId (string) --

          For nested stacks--stacks created as resources for another stack--the stack ID of the top-level stack to which the nested stack ultimately belongs.

          For more information, see Working with Nested Stacks in the CloudFormation User Guide .

        • DriftInformation (dict) --

          Information about whether a stack's actual configuration differs, or has drifted , from its expected configuration, as defined in the stack template and any values specified as template parameters. For more information, see Detecting Unregulated Configuration Changes to Stacks and Resources.

          • StackDriftStatus (string) --

            Status of the stack's actual configuration compared to its expected template configuration.

            • DRIFTED : The stack differs from its expected template configuration. A stack is considered to have drifted if one or more of its resources have drifted.

            • NOT_CHECKED : CloudFormation hasn't checked if the stack differs from its expected template configuration.

            • IN_SYNC : The stack's actual configuration matches its expected template configuration.

            • UNKNOWN : This value is reserved for future use.

          • LastCheckTimestamp (datetime) --

            Most recent time when a drift detection operation was initiated on the stack, or any of its individual resources that support drift detection.

        • RetainExceptOnCreate (boolean) --

          When set to true , newly created resources are deleted when the operation rolls back. This includes newly created resources marked with a deletion policy of Retain .

          Default: false

        • DeletionMode (string) --

          Specifies the deletion mode for the stack. Possible values are:

          • STANDARD - Use the standard behavior. Specifying this value is the same as not specifying this parameter.

          • FORCE_DELETE_STACK - Delete the stack if it's stuck in a DELETE_FAILED state due to resource deletion failure.

        • DetailedStatus (string) --

          The detailed status of the resource or stack. If CONFIGURATION_COMPLETE is present, the resource or resource configuration phase has completed and the stabilization of the resources is in progress. The stack sets CONFIGURATION_COMPLETE when all of the resources in the stack have reached that event. For more information, see CloudFormation stack deployment in the CloudFormation User Guide .

    • NextToken (string) --

      If the output exceeds 1 MB in size, a string that identifies the next page of stacks. If no additional page exists, this value is null.