diff --git a/clients/aws-sdk-cloudformation/tests/functional/__init__.py b/clients/aws-sdk-cloudformation/tests/functional/__init__.py new file mode 100644 index 00000000..04f8b7b7 --- /dev/null +++ b/clients/aws-sdk-cloudformation/tests/functional/__init__.py @@ -0,0 +1,2 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 diff --git a/clients/aws-sdk-cloudformation/tests/functional/recordings/test_create_describe_delete_stack/cloud_formation.py b/clients/aws-sdk-cloudformation/tests/functional/recordings/test_create_describe_delete_stack/cloud_formation.py new file mode 100644 index 00000000..72008d8a --- /dev/null +++ b/clients/aws-sdk-cloudformation/tests/functional/recordings/test_create_describe_delete_stack/cloud_formation.py @@ -0,0 +1,836 @@ +# Recorded by smithy_test. Review it for anything identifying before committing. +from inspect import cleandoc + +from smithy_test import HTTPMockController + + +def install(controller: HTTPMockController) -> None: + ( + controller.expect_operation("CreateStack") + .times(1) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "479", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-lifecycle-cc7dec8d/00000000-0000-4000-8000-000000000001 + 00000000-0000-4000-8000-000000000002 + + + 00000000-0000-4000-8000-000000000003 + + + """ + ), + ) + ) + ( + controller.expect_operation("DescribeStacks") + .times(12) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1775", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:30:53.434Z + + aws-sdk-python-recorded-lifecycle-cc7dec8d + aws-sdk-python recorded test + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + User Initiated + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-lifecycle-cc7dec8d/00000000-0000-4000-8000-000000000001 + CREATE_IN_PROGRESS + false + + + RecordedTest + Purpose + + + + + Delay + 1 + + + + + + + 00000000-0000-4000-8000-000000000004 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1777", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:30:53.434Z + + aws-sdk-python-recorded-lifecycle-cc7dec8d + aws-sdk-python recorded test + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-lifecycle-cc7dec8d/00000000-0000-4000-8000-000000000001 + CREATE_IN_PROGRESS + false + + + RecordedTest + Purpose + + + CONFIGURATION_COMPLETE + + + Delay + 1 + + + + + + + 00000000-0000-4000-8000-000000000005 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1777", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:30:53.434Z + + aws-sdk-python-recorded-lifecycle-cc7dec8d + aws-sdk-python recorded test + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-lifecycle-cc7dec8d/00000000-0000-4000-8000-000000000001 + CREATE_IN_PROGRESS + false + + + RecordedTest + Purpose + + + CONFIGURATION_COMPLETE + + + Delay + 1 + + + + + + + 00000000-0000-4000-8000-000000000006 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1777", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:30:53.434Z + + aws-sdk-python-recorded-lifecycle-cc7dec8d + aws-sdk-python recorded test + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-lifecycle-cc7dec8d/00000000-0000-4000-8000-000000000001 + CREATE_IN_PROGRESS + false + + + RecordedTest + Purpose + + + CONFIGURATION_COMPLETE + + + Delay + 1 + + + + + + + 00000000-0000-4000-8000-000000000007 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1777", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:30:53.434Z + + aws-sdk-python-recorded-lifecycle-cc7dec8d + aws-sdk-python recorded test + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-lifecycle-cc7dec8d/00000000-0000-4000-8000-000000000001 + CREATE_IN_PROGRESS + false + + + RecordedTest + Purpose + + + CONFIGURATION_COMPLETE + + + Delay + 1 + + + + + + + 00000000-0000-4000-8000-000000000008 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1980", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + + + QueueUrl + https://sqs.us-west-2.amazonaws.com/123456789012/aws-sdk-python-recorded-lifecycle-cc7dec8d-Queue-Ww7ayLA31siU + + + 2026-11-24T20:30:53.434Z + + aws-sdk-python-recorded-lifecycle-cc7dec8d + aws-sdk-python recorded test + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-lifecycle-cc7dec8d/00000000-0000-4000-8000-000000000001 + CREATE_COMPLETE + false + + + RecordedTest + Purpose + + + + + Delay + 1 + + + + + + + 00000000-0000-4000-8000-000000000009 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "2107", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + + + QueueUrl + https://sqs.us-west-2.amazonaws.com/123456789012/aws-sdk-python-recorded-lifecycle-cc7dec8d-Queue-Ww7ayLA31siU + + + 2026-11-24T20:30:53.434Z + + aws-sdk-python-recorded-lifecycle-cc7dec8d + aws-sdk-python recorded test + 2026-11-24T20:32:10.287Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000011 + DELETE_STACK + + + + NOT_CHECKED + + false + User Initiated + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-lifecycle-cc7dec8d/00000000-0000-4000-8000-000000000001 + DELETE_IN_PROGRESS + false + + + RecordedTest + Purpose + + + + + Delay + 1 + + + + + + + 00000000-0000-4000-8000-000000000012 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "2045", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + + + QueueUrl + https://sqs.us-west-2.amazonaws.com/123456789012/aws-sdk-python-recorded-lifecycle-cc7dec8d-Queue-Ww7ayLA31siU + + + 2026-11-24T20:30:53.434Z + + aws-sdk-python-recorded-lifecycle-cc7dec8d + aws-sdk-python recorded test + 2026-11-24T20:32:10.287Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000011 + DELETE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-lifecycle-cc7dec8d/00000000-0000-4000-8000-000000000001 + DELETE_IN_PROGRESS + false + + + RecordedTest + Purpose + + + + + Delay + 1 + + + + + + + 00000000-0000-4000-8000-000000000013 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "2045", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + + + QueueUrl + https://sqs.us-west-2.amazonaws.com/123456789012/aws-sdk-python-recorded-lifecycle-cc7dec8d-Queue-Ww7ayLA31siU + + + 2026-11-24T20:30:53.434Z + + aws-sdk-python-recorded-lifecycle-cc7dec8d + aws-sdk-python recorded test + 2026-11-24T20:32:10.287Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000011 + DELETE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-lifecycle-cc7dec8d/00000000-0000-4000-8000-000000000001 + DELETE_IN_PROGRESS + false + + + RecordedTest + Purpose + + + + + Delay + 1 + + + + + + + 00000000-0000-4000-8000-000000000014 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "2045", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + + + QueueUrl + https://sqs.us-west-2.amazonaws.com/123456789012/aws-sdk-python-recorded-lifecycle-cc7dec8d-Queue-Ww7ayLA31siU + + + 2026-11-24T20:30:53.434Z + + aws-sdk-python-recorded-lifecycle-cc7dec8d + aws-sdk-python recorded test + 2026-11-24T20:32:10.287Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000011 + DELETE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-lifecycle-cc7dec8d/00000000-0000-4000-8000-000000000001 + DELETE_IN_PROGRESS + false + + + RecordedTest + Purpose + + + + + Delay + 1 + + + + + + + 00000000-0000-4000-8000-000000000015 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "2045", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + + + QueueUrl + https://sqs.us-west-2.amazonaws.com/123456789012/aws-sdk-python-recorded-lifecycle-cc7dec8d-Queue-Ww7ayLA31siU + + + 2026-11-24T20:30:53.434Z + + aws-sdk-python-recorded-lifecycle-cc7dec8d + aws-sdk-python recorded test + 2026-11-24T20:32:10.287Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000011 + DELETE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-lifecycle-cc7dec8d/00000000-0000-4000-8000-000000000001 + DELETE_IN_PROGRESS + false + + + RecordedTest + Purpose + + + + + Delay + 1 + + + + + + + 00000000-0000-4000-8000-000000000016 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1969", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + + + QueueUrl + https://sqs.us-west-2.amazonaws.com/123456789012/aws-sdk-python-recorded-lifecycle-cc7dec8d-Queue-Ww7ayLA31siU + + + 2026-11-24T20:30:53.434Z + + aws-sdk-python-recorded-lifecycle-cc7dec8d + aws-sdk-python recorded test + 2026-11-24T20:32:10.287Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000011 + DELETE_STACK + + + + NOT_CHECKED + + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-lifecycle-cc7dec8d/00000000-0000-4000-8000-000000000001 + DELETE_COMPLETE + false + + + RecordedTest + Purpose + + + + + Delay + 1 + + + + + + + 00000000-0000-4000-8000-000000000017 + + + """ + ), + ) + ) + ( + controller.expect_operation("DeleteStack") + .times(1) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "211", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + 00000000-0000-4000-8000-000000000010 + + + """ + ), + ) + ) diff --git a/clients/aws-sdk-cloudformation/tests/functional/recordings/test_failed_create_rolls_back_with_reason/cloud_formation.py b/clients/aws-sdk-cloudformation/tests/functional/recordings/test_failed_create_rolls_back_with_reason/cloud_formation.py new file mode 100644 index 00000000..97eeca4d --- /dev/null +++ b/clients/aws-sdk-cloudformation/tests/functional/recordings/test_failed_create_rolls_back_with_reason/cloud_formation.py @@ -0,0 +1,899 @@ +# Recorded by smithy_test. Review it for anything identifying before committing. +from inspect import cleandoc + +from smithy_test import HTTPMockController + + +def install(controller: HTTPMockController) -> None: + ( + controller.expect_operation("CreateStack") + .times(1) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "478", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + 00000000-0000-4000-8000-000000000002 + + + 00000000-0000-4000-8000-000000000003 + + + """ + ), + ) + ) + ( + controller.expect_operation("DescribeStacks") + .times(14) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1408", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:36:01.162Z + + aws-sdk-python-recorded-rollback-7ebfbcac + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + User Initiated + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + CREATE_IN_PROGRESS + false + + + + + + 00000000-0000-4000-8000-000000000004 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1577", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:36:01.162Z + + aws-sdk-python-recorded-rollback-7ebfbcac + 2026-11-24T20:36:04.955Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000005 + ROLLBACK + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + ROLLBACK_IN_PROGRESS + false + + + + + + 00000000-0000-4000-8000-000000000006 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1577", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:36:01.162Z + + aws-sdk-python-recorded-rollback-7ebfbcac + 2026-11-24T20:36:04.955Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000005 + ROLLBACK + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + ROLLBACK_IN_PROGRESS + false + + + + + + 00000000-0000-4000-8000-000000000007 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1577", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:36:01.162Z + + aws-sdk-python-recorded-rollback-7ebfbcac + 2026-11-24T20:36:04.955Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000005 + ROLLBACK + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + ROLLBACK_IN_PROGRESS + false + + + + + + 00000000-0000-4000-8000-000000000008 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1577", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:36:01.162Z + + aws-sdk-python-recorded-rollback-7ebfbcac + 2026-11-24T20:36:04.955Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000005 + ROLLBACK + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + ROLLBACK_IN_PROGRESS + false + + + + + + 00000000-0000-4000-8000-000000000009 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1577", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:36:01.162Z + + aws-sdk-python-recorded-rollback-7ebfbcac + 2026-11-24T20:36:04.955Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000005 + ROLLBACK + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + ROLLBACK_IN_PROGRESS + false + + + + + + 00000000-0000-4000-8000-000000000010 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1577", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:36:01.162Z + + aws-sdk-python-recorded-rollback-7ebfbcac + 2026-11-24T20:36:04.955Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000005 + ROLLBACK + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + ROLLBACK_IN_PROGRESS + false + + + + + + 00000000-0000-4000-8000-000000000011 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1577", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:36:01.162Z + + aws-sdk-python-recorded-rollback-7ebfbcac + 2026-11-24T20:36:04.955Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000005 + ROLLBACK + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + ROLLBACK_IN_PROGRESS + false + + + + + + 00000000-0000-4000-8000-000000000012 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1577", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:36:01.162Z + + aws-sdk-python-recorded-rollback-7ebfbcac + 2026-11-24T20:36:04.955Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000005 + ROLLBACK + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + ROLLBACK_IN_PROGRESS + false + + + + + + 00000000-0000-4000-8000-000000000013 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1577", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:36:01.162Z + + aws-sdk-python-recorded-rollback-7ebfbcac + 2026-11-24T20:36:04.955Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000005 + ROLLBACK + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + ROLLBACK_IN_PROGRESS + false + + + + + + 00000000-0000-4000-8000-000000000014 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1577", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:36:01.162Z + + aws-sdk-python-recorded-rollback-7ebfbcac + 2026-11-24T20:36:04.955Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000005 + ROLLBACK + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + ROLLBACK_IN_PROGRESS + false + + + + + + 00000000-0000-4000-8000-000000000015 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1574", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:36:01.162Z + + aws-sdk-python-recorded-rollback-7ebfbcac + 2026-11-24T20:36:04.955Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000005 + ROLLBACK + + + 00000000-0000-4000-8000-000000000002 + CREATE_STACK + + + + NOT_CHECKED + + false + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + ROLLBACK_COMPLETE + false + + + + + + 00000000-0000-4000-8000-000000000016 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1470", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:36:01.162Z + + aws-sdk-python-recorded-rollback-7ebfbcac + 2026-11-24T20:38:49.963Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000022 + DELETE_STACK + + + + NOT_CHECKED + + false + User Initiated + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + DELETE_IN_PROGRESS + false + + + + + + 00000000-0000-4000-8000-000000000023 + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "1332", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 2026-11-24T20:36:01.162Z + + aws-sdk-python-recorded-rollback-7ebfbcac + 2026-11-24T20:38:49.963Z + + STANDARD + false + + + + + 00000000-0000-4000-8000-000000000022 + DELETE_STACK + + + + NOT_CHECKED + + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + DELETE_COMPLETE + false + + + + + + 00000000-0000-4000-8000-000000000024 + + + """ + ), + ) + ) + ( + controller.expect_operation("DescribeStackEvents") + .times(1) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "6311", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + + + 00000000-0000-4000-8000-000000000017 + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + aws-sdk-python-recorded-rollback-7ebfbcac + aws-sdk-python-recorded-rollback-7ebfbcac + ROLLBACK_COMPLETE + 00000000-0000-4000-8000-000000000003 + 00000000-0000-4000-8000-000000000005 + 2026-11-24T20:38:36.483Z + AWS::CloudFormation::Stack + + + Queue-DELETE_COMPLETE-2026-11-24T20:38:36.155Z + + {"QueueName":"aws-sdk-python-recorded-invalid.fifo"} + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + aws-sdk-python-recorded-rollback-7ebfbcac + Queue + DELETE_COMPLETE + 00000000-0000-4000-8000-000000000003 + 00000000-0000-4000-8000-000000000005 + 2026-11-24T20:38:36.155Z + AWS::SQS::Queue + + + 00000000-0000-4000-8000-000000000018 + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + The following resource(s) failed to create: [Queue]. Rollback requested by user. + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + aws-sdk-python-recorded-rollback-7ebfbcac + aws-sdk-python-recorded-rollback-7ebfbcac + ROLLBACK_IN_PROGRESS + 00000000-0000-4000-8000-000000000003 + 00000000-0000-4000-8000-000000000005 + 2026-11-24T20:36:04.955Z + AWS::CloudFormation::Stack + + + Queue-CREATE_FAILED-2026-11-24T20:36:04.675Z + + Resource handler returned message: "Can only include alphanumeric characters, hyphens, or underscores. 1 to 80 in length (Service: Sqs, Status Code: 400, Request ID: 00000000-0000-4000-8000-000000000019) (SDK Attempt Count: 1)" (RequestToken: 02c244a4-4818-d489-9d1c-767bbd2ea8ce, HandlerErrorCode: GeneralServiceException) + {"QueueName":"aws-sdk-python-recorded-invalid.fifo"} + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + aws-sdk-python-recorded-rollback-7ebfbcac + Queue + CREATE_FAILED + 00000000-0000-4000-8000-000000000003 + 00000000-0000-4000-8000-000000000002 + 2026-11-24T20:36:04.675Z + AWS::SQS::Queue + + + Queue-CREATE_IN_PROGRESS-2026-11-24T20:36:03.892Z + + {"QueueName":"aws-sdk-python-recorded-invalid.fifo"} + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + aws-sdk-python-recorded-rollback-7ebfbcac + Queue + CREATE_IN_PROGRESS + 00000000-0000-4000-8000-000000000003 + 00000000-0000-4000-8000-000000000002 + 2026-11-24T20:36:03.892Z + AWS::SQS::Queue + + + 00000000-0000-4000-8000-000000000002 + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + User Initiated + arn:aws:cloudformation:us-west-2:123456789012:stack/aws-sdk-python-recorded-rollback-7ebfbcac/00000000-0000-4000-8000-000000000001 + aws-sdk-python-recorded-rollback-7ebfbcac + aws-sdk-python-recorded-rollback-7ebfbcac + CREATE_IN_PROGRESS + 00000000-0000-4000-8000-000000000003 + 00000000-0000-4000-8000-000000000002 + 2026-11-24T20:36:01.162Z + AWS::CloudFormation::Stack + + + + + 00000000-0000-4000-8000-000000000020 + + + """ + ), + ) + ) + ( + controller.expect_operation("DeleteStack") + .times(1) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "211", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + 00000000-0000-4000-8000-000000000021 + + + """ + ), + ) + ) diff --git a/clients/aws-sdk-cloudformation/tests/functional/recordings/test_validate_template_reports_parameters_and_description/cloud_formation.py b/clients/aws-sdk-cloudformation/tests/functional/recordings/test_validate_template_reports_parameters_and_description/cloud_formation.py new file mode 100644 index 00000000..77215e59 --- /dev/null +++ b/clients/aws-sdk-cloudformation/tests/functional/recordings/test_validate_template_reports_parameters_and_description/cloud_formation.py @@ -0,0 +1,41 @@ +# Recorded by smithy_test. Review it for anything identifying before committing. +from inspect import cleandoc + +from smithy_test import HTTPMockController + + +def install(controller: HTTPMockController) -> None: + ( + controller.expect_operation("ValidateTemplate") + .times(1) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "Strict-Transport-Security": "max-age=47304000; includeSubDomains", + "Cache-Control": "no-store, no-cache", + "Content-Type": "text/xml", + "Content-Length": "515", + "connection": "keep-alive", + }, + body=cleandoc( + r""" + + + aws-sdk-python recorded test + + + false + 0 + Delay + + + + + 00000000-0000-4000-8000-000000000001 + + + """ + ), + ) + ) diff --git a/clients/aws-sdk-cloudformation/tests/functional/test_recorded_stacks.py b/clients/aws-sdk-cloudformation/tests/functional/test_recorded_stacks.py new file mode 100644 index 00000000..fc990223 --- /dev/null +++ b/clients/aws-sdk-cloudformation/tests/functional/test_recorded_stacks.py @@ -0,0 +1,180 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +"""Stack lifecycle and validation, replayed from recordings of the live service. + +Record against AWS with ``SMITHY_PYTHON_TEST_MODE=record pytest ``. + +The recordings are in ``recordings//cloud_formation.py``. Each serves +both clients, because playback answers by operation and never looks at the request. +Stack names need a unique suffix, so a test compares only their prefix: the recording +holds the name it was recorded with. +""" + +import json +import os +from collections.abc import AsyncIterator +from contextlib import AsyncExitStack +from pathlib import Path +from typing import cast +from uuid import uuid4 + +import pytest +from aws_sdk_cloudformation.aio.client import AsyncCloudFormationClient +from aws_sdk_cloudformation.aio.config import AsyncCloudFormationConfig +from aws_sdk_cloudformation.client import CloudFormationClient +from aws_sdk_cloudformation.config import CloudFormationConfig +from aws_sdk_cloudformation.models import Stack +from dual_mode import MODES, AwaitableClient, Mode +from smithy_test import instrument +from smithy_test.aio import instrument_async +from waiters import wait_until + +REGION = "us-west-2" +RECORDING = os.environ.get("SMITHY_PYTHON_TEST_MODE") == "record" +# Playback answers at once, so there is nothing to wait for. +POLL_INTERVAL = 15 if RECORDING else 0 + +QUEUE_TEMPLATE = json.dumps( + { + "Description": "aws-sdk-python recorded test", + "Parameters": {"Delay": {"Type": "Number", "Default": 0}}, + "Resources": { + "Queue": { + "Type": "AWS::SQS::Queue", + "Properties": {"DelaySeconds": {"Ref": "Delay"}}, + } + }, + "Outputs": {"QueueUrl": {"Value": {"Ref": "Queue"}}}, + } +) + +# A fifo-suffixed name without FifoQueue=true is rejected by SQS during creation. +FAILING_TEMPLATE = json.dumps( + { + "Resources": { + "Queue": { + "Type": "AWS::SQS::Queue", + "Properties": {"QueueName": "aws-sdk-python-recorded-invalid.fifo"}, + } + } + } +) + + +@pytest.fixture(params=MODES) +def mode(request: pytest.FixtureRequest) -> Mode: + return cast(Mode, request.param) + + +@pytest.fixture +async def cloudformation( + mode: Mode, request: pytest.FixtureRequest +) -> AsyncIterator[AsyncCloudFormationClient]: + """A client in the test's mode, recorded or replayed per test function.""" + name = cast(pytest.Function, request.node).originalname + path = Path(__file__).parent / "recordings" / name / "cloud_formation.py" + async with AsyncExitStack() as stack: + if mode == "async": + client = AsyncCloudFormationClient( + await AsyncCloudFormationConfig.resolve(region=REGION) + ) + await stack.enter_async_context(client) + await stack.enter_async_context(await instrument_async(client, path=path)) + yield client + else: + sync = CloudFormationClient(CloudFormationConfig.resolve(region=REGION)) + stack.enter_context(instrument(sync, path=path)) + adapter = await stack.enter_async_context(AwaitableClient(sync)) + yield cast(AsyncCloudFormationClient, adapter) + + +async def test_create_describe_delete_stack( + cloudformation: AsyncCloudFormationClient, +) -> None: + """A stack created with a parameter and tag reaches CREATE_COMPLETE with its outputs, then deletes.""" + prefix = "aws-sdk-python-recorded-lifecycle" + created = await cloudformation.create_stack( + stack_name=f"{prefix}-{uuid4().hex[:8]}", + template_body=QUEUE_TEMPLATE, + parameters=[{"parameter_key": "Delay", "parameter_value": "1"}], + tags=[{"key": "Purpose", "value": "RecordedTest"}], + ) + assert created.stack_id + + stack = await _wait_for_status(cloudformation, created.stack_id, "CREATE_COMPLETE") + assert (stack.stack_name or "").startswith(prefix) + assert stack.stack_id == created.stack_id + assert [(p.parameter_key, p.parameter_value) for p in stack.parameters or []] == [ + ("Delay", "1") + ] + assert [(t.key, t.value) for t in stack.tags or []] == [("Purpose", "RecordedTest")] + outputs = {o.output_key: o.output_value for o in stack.outputs or []} + assert (outputs["QueueUrl"] or "").startswith("https://sqs.") + + await cloudformation.delete_stack(stack_name=created.stack_id) + # Deleted stacks stay describable by ID only. + deleted = await _wait_for_status( + cloudformation, created.stack_id, "DELETE_COMPLETE" + ) + assert deleted.deletion_time is not None + + +async def test_failed_create_rolls_back_with_reason( + cloudformation: AsyncCloudFormationClient, +) -> None: + """A stack whose resource fails to create rolls back and records the failure in its events.""" + created = await cloudformation.create_stack( + stack_name=f"aws-sdk-python-recorded-rollback-{uuid4().hex[:8]}", + template_body=FAILING_TEMPLATE, + ) + assert created.stack_id + try: + await _wait_for_status(cloudformation, created.stack_id, "ROLLBACK_COMPLETE") + + events = await cloudformation.describe_stack_events(stack_name=created.stack_id) + failures = [ + e + for e in events.stack_events or [] + if e.resource_status == "CREATE_FAILED" and e.logical_resource_id == "Queue" + ] + assert failures + assert failures[0].resource_status_reason + finally: + await cloudformation.delete_stack(stack_name=created.stack_id) + await _wait_for_status(cloudformation, created.stack_id, "DELETE_COMPLETE") + + +async def test_validate_template_reports_parameters_and_description( + cloudformation: AsyncCloudFormationClient, +) -> None: + """ValidateTemplate returns the template's description and parameter declarations.""" + result = await cloudformation.validate_template(template_body=QUEUE_TEMPLATE) + assert result.description == "aws-sdk-python recorded test" + assert [(p.parameter_key, p.default_value) for p in result.parameters or []] == [ + ("Delay", "0") + ] + + +async def _wait_for_status( + client: AsyncCloudFormationClient, stack_id: str, target: str +) -> Stack: + """Wait for the stack to reach ``target``, failing at once on any other settled status.""" + + async def describe() -> Stack: + output = await client.describe_stacks(stack_name=stack_id) + assert output.stacks + return output.stacks[0] + + def reached_target(stack: Stack) -> bool: + status = stack.stack_status or "" + if status == target: + return True + assert status.endswith("_IN_PROGRESS"), ( + f"stack reached {status}: {stack.stack_status_reason}" + ) + return False + + return await wait_until( + describe, reached_target, interval=POLL_INTERVAL, timeout=600 + ) diff --git a/clients/aws-sdk-dynamodb/tests/functional/recordings/test_table_and_item_crud/dynamo_db.py b/clients/aws-sdk-dynamodb/tests/functional/recordings/test_table_and_item_crud/dynamo_db.py new file mode 100644 index 00000000..93b6f435 --- /dev/null +++ b/clients/aws-sdk-dynamodb/tests/functional/recordings/test_table_and_item_crud/dynamo_db.py @@ -0,0 +1,1026 @@ +# Recorded by smithy_test. Review it for anything identifying before committing. +from inspect import cleandoc + +from smithy_test import HTTPMockController + + +def install(controller: HTTPMockController) -> None: + ( + controller.expect_operation("CreateTable") + .times(1) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "901", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "517962360", + }, + body=cleandoc( + r""" + { + "TableDescription": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST" + }, + "CreationDateTime": 1795547063.215, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "CREATING", + "TableThroughputModeSummary": { + "TableThroughputMode": "PAY_PER_REQUEST" + } + } + } + """ + ), + ) + ) + ( + controller.expect_operation("DescribeTable") + .times(14) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "890", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2565307401", + }, + body=cleandoc( + r""" + { + "Table": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST" + }, + "CreationDateTime": 1795547063.215, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "CREATING", + "TableThroughputModeSummary": { + "TableThroughputMode": "PAY_PER_REQUEST" + } + } + } + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "890", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2565307401", + }, + body=cleandoc( + r""" + { + "Table": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST" + }, + "CreationDateTime": 1795547063.215, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "CREATING", + "TableThroughputModeSummary": { + "TableThroughputMode": "PAY_PER_REQUEST" + } + } + } + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "890", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2565307401", + }, + body=cleandoc( + r""" + { + "Table": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST" + }, + "CreationDateTime": 1795547063.215, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "CREATING", + "TableThroughputModeSummary": { + "TableThroughputMode": "PAY_PER_REQUEST" + } + } + } + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "890", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2565307401", + }, + body=cleandoc( + r""" + { + "Table": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST" + }, + "CreationDateTime": 1795547063.215, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "CREATING", + "TableThroughputModeSummary": { + "TableThroughputMode": "PAY_PER_REQUEST" + } + } + } + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "890", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2565307401", + }, + body=cleandoc( + r""" + { + "Table": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST" + }, + "CreationDateTime": 1795547063.215, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "CREATING", + "TableThroughputModeSummary": { + "TableThroughputMode": "PAY_PER_REQUEST" + } + } + } + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "890", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2565307401", + }, + body=cleandoc( + r""" + { + "Table": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST" + }, + "CreationDateTime": 1795547063.215, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "CREATING", + "TableThroughputModeSummary": { + "TableThroughputMode": "PAY_PER_REQUEST" + } + } + } + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "890", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2565307401", + }, + body=cleandoc( + r""" + { + "Table": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST" + }, + "CreationDateTime": 1795547063.215, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "CREATING", + "TableThroughputModeSummary": { + "TableThroughputMode": "PAY_PER_REQUEST" + } + } + } + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "890", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2565307401", + }, + body=cleandoc( + r""" + { + "Table": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST" + }, + "CreationDateTime": 1795547063.215, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "CREATING", + "TableThroughputModeSummary": { + "TableThroughputMode": "PAY_PER_REQUEST" + } + } + } + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "890", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2565307401", + }, + body=cleandoc( + r""" + { + "Table": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST" + }, + "CreationDateTime": 1795547063.215, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "CREATING", + "TableThroughputModeSummary": { + "TableThroughputMode": "PAY_PER_REQUEST" + } + } + } + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "890", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2565307401", + }, + body=cleandoc( + r""" + { + "Table": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST" + }, + "CreationDateTime": 1795547063.215, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "CREATING", + "TableThroughputModeSummary": { + "TableThroughputMode": "PAY_PER_REQUEST" + } + } + } + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "890", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2565307401", + }, + body=cleandoc( + r""" + { + "Table": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST" + }, + "CreationDateTime": 1795547063.215, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "CREATING", + "TableThroughputModeSummary": { + "TableThroughputMode": "PAY_PER_REQUEST" + } + } + } + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "890", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2565307401", + }, + body=cleandoc( + r""" + { + "Table": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST" + }, + "CreationDateTime": 1795547063.215, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "CREATING", + "TableThroughputModeSummary": { + "TableThroughputMode": "PAY_PER_REQUEST" + } + } + } + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "890", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2565307401", + }, + body=cleandoc( + r""" + { + "Table": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST" + }, + "CreationDateTime": 1795547063.215, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "CREATING", + "TableThroughputModeSummary": { + "TableThroughputMode": "PAY_PER_REQUEST" + } + } + } + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "1132", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "780005708", + }, + body=cleandoc( + r""" + { + "Table": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST", + "LastUpdateToPayPerRequestDateTime": 1795547063.215 + }, + "CreationDateTime": 1795547063.215, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "ACTIVE", + "TableThroughputModeSummary": { + "LastUpdateToPayPerRequestDateTime": 1795547063.215, + "TableThroughputMode": "PAY_PER_REQUEST" + }, + "WarmThroughput": { + "ReadUnitsPerSecond": 12000, + "Status": "ACTIVE", + "WriteUnitsPerSecond": 4000 + } + } + } + """ + ), + ) + ) + ( + controller.expect_operation("PutItem") + .times(1) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "2", + "Connection": "keep-alive", + "x-amzn-requestid": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2745614147", + }, + body=cleandoc( + r""" + {} + """ + ), + ) + ) + ( + controller.expect_operation("GetItem") + .times(3) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "304", + "Connection": "keep-alive", + "x-amzn-requestid": "RECORDED-REQUEST-ID", + "x-amz-crc32": "3462548770", + }, + body=cleandoc( + r""" + { + "Item": { + "count": { + "N": "1" + }, + "id": { + "S": "a" + }, + "tags": { + "SS": [ + "x", + "y" + ] + }, + "profile": { + "M": { + "admin": { + "BOOL": true + }, + "name": { + "S": "Ann" + } + } + } + } + } + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "304", + "Connection": "keep-alive", + "x-amzn-requestid": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2515338361", + }, + body=cleandoc( + r""" + { + "Item": { + "count": { + "N": "2" + }, + "id": { + "S": "a" + }, + "profile": { + "M": { + "admin": { + "BOOL": true + }, + "name": { + "S": "Ann" + } + } + }, + "tags": { + "SS": [ + "x", + "y" + ] + } + } + } + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "2", + "Connection": "keep-alive", + "x-amzn-requestid": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2745614147", + }, + body=cleandoc( + r""" + {} + """ + ), + ) + ) + ( + controller.expect_operation("UpdateItem") + .times(1) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "2", + "Connection": "keep-alive", + "x-amzn-requestid": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2745614147", + }, + body=cleandoc( + r""" + {} + """ + ), + ) + ) + ( + controller.expect_operation("Scan") + .times(1) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "396", + "Connection": "keep-alive", + "x-amzn-requestid": "RECORDED-REQUEST-ID", + "x-amz-crc32": "3072308734", + }, + body=cleandoc( + r""" + { + "Count": 1, + "Items": [ + { + "count": { + "N": "2" + }, + "id": { + "S": "a" + }, + "profile": { + "M": { + "admin": { + "BOOL": true + }, + "name": { + "S": "Ann" + } + } + }, + "tags": { + "SS": [ + "x", + "y" + ] + } + } + ], + "ScannedCount": 1 + } + """ + ), + ) + ) + ( + controller.expect_operation("DeleteItem") + .times(1) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "2", + "Connection": "keep-alive", + "x-amzn-requestid": "RECORDED-REQUEST-ID", + "x-amz-crc32": "2745614147", + }, + body=cleandoc( + r""" + {} + """ + ), + ) + ) + ( + controller.expect_operation("DeleteTable") + .times(1) + .respond_with( + status_code=200, + headers={ + "Server": "Server", + "Content-Type": "application/x-amz-json-1.0", + "Content-Length": "767", + "Connection": "keep-alive", + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "x-amz-crc32": "1511882710", + }, + body=cleandoc( + r""" + { + "TableDescription": { + "BillingModeSummary": { + "BillingMode": "PAY_PER_REQUEST", + "LastUpdateToPayPerRequestDateTime": 1795547063.215 + }, + "DeletionProtectionEnabled": false, + "ItemCount": 0, + "ProvisionedThroughput": { + "NumberOfDecreasesToday": 0, + "ReadCapacityUnits": 0, + "WriteCapacityUnits": 0 + }, + "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/aws-sdk-python-recorded-fe642932", + "TableId": "00000000-0000-4000-8000-000000000001", + "TableName": "aws-sdk-python-recorded-fe642932", + "TableSizeBytes": 0, + "TableStatus": "DELETING", + "TableThroughputModeSummary": { + "LastUpdateToPayPerRequestDateTime": 1795547063.215, + "TableThroughputMode": "PAY_PER_REQUEST" + } + } + } + """ + ), + ) + ) diff --git a/clients/aws-sdk-dynamodb/tests/functional/test_recorded_crud.py b/clients/aws-sdk-dynamodb/tests/functional/test_recorded_crud.py new file mode 100644 index 00000000..595d52b2 --- /dev/null +++ b/clients/aws-sdk-dynamodb/tests/functional/test_recorded_crud.py @@ -0,0 +1,103 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +"""Table and item CRUD, replayed from a recording of the live service. + +Record against AWS with ``SMITHY_PYTHON_TEST_MODE=record pytest ``. + +The recording is in ``recordings//.py``. It serves both clients, +because playback answers by operation and never looks at the request. +""" + +from collections.abc import Mapping +import os +from contextlib import AsyncExitStack +from typing import cast +from uuid import uuid4 + +import pytest +from aws_sdk_dynamodb.aio.client import AsyncDynamoDBClient +from aws_sdk_dynamodb.aio.config import AsyncDynamoDBConfig +from aws_sdk_dynamodb.client import DynamoDBClient +from aws_sdk_dynamodb.config import DynamoDBConfig +from aws_sdk_dynamodb.models import AttributeValue, AttributeValueDict, AttributeValueN +from dual_mode import MODES, AwaitableClient, Mode +from smithy_test import instrument +from smithy_test.aio import instrument_async +from waiters import wait_until + +REGION = "us-west-2" +RECORDING = os.environ.get("SMITHY_PYTHON_TEST_MODE") == "record" + + +@pytest.mark.parametrize("mode", MODES) +async def test_table_and_item_crud(mode: Mode) -> None: + table = f"aws-sdk-python-recorded-{uuid4().hex[:8]}" + + async with AsyncExitStack() as stack: + if mode == "async": + client = AsyncDynamoDBClient( + await AsyncDynamoDBConfig.resolve(region=REGION) + ) + await stack.enter_async_context(client) + await stack.enter_async_context(await instrument_async(client)) + ddb = client + else: + sync = DynamoDBClient(DynamoDBConfig.resolve(region=REGION)) + stack.enter_context(instrument(sync)) + adapter = await stack.enter_async_context(AwaitableClient(sync)) + ddb = cast(AsyncDynamoDBClient, adapter) + + await ddb.create_table( + table_name=table, + attribute_definitions=[{"attribute_name": "id", "attribute_type": "S"}], + key_schema=[{"attribute_name": "id", "key_type": "HASH"}], + billing_mode="PAY_PER_REQUEST", + ) + try: + await wait_until( + lambda: ddb.describe_table(table_name=table), + lambda described: ( + described.table is not None + and described.table.table_status == "ACTIVE" + ), + # Playback answers at once, so there is nothing to wait for. + interval=0.5 if RECORDING else 0, + ) + + item: Mapping[str, AttributeValue | AttributeValueDict] = { + "id": {"s": "a"}, + "count": {"n": "1"}, + "profile": {"m": {"name": {"s": "Ann"}, "admin": {"bool_": True}}}, + "tags": {"ss": ["x", "y"]}, + } + await ddb.put_item(table_name=table, item=item) + got = await ddb.get_item( + table_name=table, key={"id": {"s": "a"}}, consistent_read=True + ) + assert got.item is not None + assert got.item["count"] == AttributeValueN("1") + + await ddb.update_item( + table_name=table, + key={"id": {"s": "a"}}, + update_expression="SET #c = #c + :one", + expression_attribute_names={"#c": "count"}, + expression_attribute_values={":one": {"n": "1"}}, + ) + updated = await ddb.get_item( + table_name=table, key={"id": {"s": "a"}}, consistent_read=True + ) + assert updated.item is not None + assert updated.item["count"] == AttributeValueN("2") + + scanned = await ddb.scan(table_name=table, consistent_read=True) + assert scanned.count == 1 + + await ddb.delete_item(table_name=table, key={"id": {"s": "a"}}) + gone = await ddb.get_item( + table_name=table, key={"id": {"s": "a"}}, consistent_read=True + ) + assert not gone.item + finally: + await ddb.delete_table(table_name=table) diff --git a/clients/aws-sdk-s3/pyproject.toml b/clients/aws-sdk-s3/pyproject.toml index d1945e16..38ec627d 100644 --- a/clients/aws-sdk-s3/pyproject.toml +++ b/clients/aws-sdk-s3/pyproject.toml @@ -36,9 +36,10 @@ awscrt = [ [dependency-groups] test = [ + "aws-sdk-sts", "pytest>=9.0.3,<10.0.0", "pytest-asyncio>=1.3.0,<1.4.0", - "smithy_test~=0.5.0" + "smithy_test~=0.5.0", ] [build-system] @@ -71,3 +72,6 @@ skip-magic-trailing-comma = true pythonpath = ["../../tests"] python_classes = ["!Test"] asyncio_mode = "auto" + +[tool.uv.sources] +aws-sdk-sts = { path = "../aws-sdk-sts", editable = true } diff --git a/clients/aws-sdk-s3/tests/functional/recordings/test_bucket_and_object_crud/s3.py b/clients/aws-sdk-s3/tests/functional/recordings/test_bucket_and_object_crud/s3.py new file mode 100644 index 00000000..bbdfd1b1 --- /dev/null +++ b/clients/aws-sdk-s3/tests/functional/recordings/test_bucket_and_object_crud/s3.py @@ -0,0 +1,236 @@ +# Recorded by smithy_test. Review it for anything identifying before committing. +from inspect import cleandoc + +from smithy_test import HTTPMockController + + +def install(controller: HTTPMockController) -> None: + ( + controller.expect_operation("CreateBucket") + .times(1) + .respond_with( + status_code=200, + headers={ + "x-amz-id-2": "RECORDED-HOST-ID", + "x-amz-request-id": "RECORDED-REQUEST-ID", + "Server": "AmazonS3", + "Location": "/aws-sdk-python-recorded-5e390e7d-111122223333-us-west-2-an", + "x-amz-bucket-arn": "arn:aws:s3:::aws-sdk-python-recorded-5e390e7d-111122223333-us-west-2-an", + "Content-Length": "0", + }, + body=b"", + ) + ) + ( + controller.expect_operation("HeadBucket") + .times(1) + .respond_with( + status_code=200, + headers={ + "x-amz-id-2": "RECORDED-HOST-ID", + "x-amz-request-id": "RECORDED-REQUEST-ID", + "Server": "AmazonS3", + "x-amz-bucket-region": "us-west-2", + "x-amz-access-point-alias": "false", + "x-amz-bucket-arn": "arn:aws:s3:::aws-sdk-python-recorded-5e390e7d-111122223333-us-west-2-an", + "Content-Type": "application/xml", + "Transfer-Encoding": "chunked", + }, + body=b"", + ) + ) + ( + controller.expect_operation("PutObject") + .times(1) + .respond_with( + status_code=200, + headers={ + "x-amz-id-2": "RECORDED-HOST-ID", + "x-amz-request-id": "RECORDED-REQUEST-ID", + "Server": "AmazonS3", + "x-amz-server-side-encryption": "AES256", + "ETag": '"5d41402abc4b2a76b9719d911017c592"', + "x-amz-checksum-crc64nvme": "M3eFcAZSQlc=", + "x-amz-checksum-type": "FULL_OBJECT", + "Content-Length": "0", + }, + body=b"", + ) + ) + ( + controller.expect_operation("GetObject") + .times(1) + .respond_with( + status_code=200, + headers={ + "x-amz-request-id": "RECORDED-REQUEST-ID", + "x-amz-id-2": "RECORDED-HOST-ID", + "Content-Length": "5", + "Accept-Ranges": "bytes", + "Server": "AmazonS3", + "Last-Modified": "Tue, 24 Nov 2026 19:04:14 GMT", + "ETag": '"5d41402abc4b2a76b9719d911017c592"', + "x-amz-checksum-crc64nvme": "M3eFcAZSQlc=", + "x-amz-checksum-type": "FULL_OBJECT", + "x-amz-meta-k": "v", + "Content-Type": "application/octet-stream", + "x-amz-server-side-encryption": "AES256", + }, + body=b"hello", + ) + ) + ( + controller.expect_operation("HeadObject") + .times(1) + .respond_with( + status_code=200, + headers={ + "x-amz-id-2": "RECORDED-HOST-ID", + "x-amz-request-id": "RECORDED-REQUEST-ID", + "Server": "AmazonS3", + "Last-Modified": "Tue, 24 Nov 2026 19:04:14 GMT", + "ETag": '"5d41402abc4b2a76b9719d911017c592"', + "x-amz-server-side-encryption": "AES256", + "x-amz-meta-k": "v", + "Accept-Ranges": "bytes", + "Content-Length": "5", + "Content-Type": "application/octet-stream", + }, + body=b"", + ) + ) + ( + controller.expect_operation("CopyObject") + .times(1) + .respond_with( + status_code=200, + headers={ + "x-amz-id-2": "RECORDED-HOST-ID", + "x-amz-request-id": "RECORDED-REQUEST-ID", + "Server": "AmazonS3", + "x-amz-server-side-encryption": "AES256", + "Content-Length": "338", + "Content-Type": "application/xml", + }, + body=cleandoc( + r""" + + + 2026-11-24T19:04:14.000Z + "5d41402abc4b2a76b9719d911017c592" + M3eFcAZSQlc= + FULL_OBJECT + + """ + ), + ) + ) + ( + controller.expect_operation("ListObjectsV2") + .times(2) + .respond_with( + status_code=200, + headers={ + "x-amz-id-2": "RECORDED-HOST-ID", + "x-amz-request-id": "RECORDED-REQUEST-ID", + "Server": "AmazonS3", + "x-amz-bucket-region": "us-west-2", + "Content-Type": "application/xml", + "Transfer-Encoding": "chunked", + }, + body=cleandoc( + r""" + + + aws-sdk-python-recorded-5e390e7d-111122223333-us-west-2-an + a/ + 2 + 1000 + false + + a/1.txt + 2026-11-24T19:04:14.000Z + "5d41402abc4b2a76b9719d911017c592" + CRC64NVME + FULL_OBJECT + 5 + STANDARD + + + a/2.txt + 2026-11-24T19:04:14.000Z + "5d41402abc4b2a76b9719d911017c592" + CRC64NVME + FULL_OBJECT + 5 + STANDARD + + + """ + ), + ) + .respond_with( + status_code=200, + headers={ + "x-amz-id-2": "RECORDED-HOST-ID", + "x-amz-request-id": "RECORDED-REQUEST-ID", + "Server": "AmazonS3", + "x-amz-bucket-region": "us-west-2", + "Content-Type": "application/xml", + "Transfer-Encoding": "chunked", + }, + body=cleandoc( + r""" + + + aws-sdk-python-recorded-5e390e7d-111122223333-us-west-2-an + + 0 + 1000 + false + + """ + ), + ) + ) + ( + controller.expect_operation("DeleteObjects") + .times(1) + .respond_with( + status_code=200, + headers={ + "x-amz-id-2": "RECORDED-HOST-ID", + "x-amz-request-id": "RECORDED-REQUEST-ID", + "Server": "AmazonS3", + "Connection": "close", + "Content-Type": "application/xml", + "Transfer-Encoding": "chunked", + }, + body=cleandoc( + r""" + + + + a/2.txt + + + a/1.txt + + + """ + ), + ) + ) + ( + controller.expect_operation("DeleteBucket") + .times(1) + .respond_with( + status_code=204, + headers={ + "x-amz-id-2": "RECORDED-HOST-ID", + "x-amz-request-id": "RECORDED-REQUEST-ID", + "Server": "AmazonS3", + }, + body=b"", + ) + ) diff --git a/clients/aws-sdk-s3/tests/functional/recordings/test_bucket_and_object_crud/sts.py b/clients/aws-sdk-s3/tests/functional/recordings/test_bucket_and_object_crud/sts.py new file mode 100644 index 00000000..b819a71c --- /dev/null +++ b/clients/aws-sdk-s3/tests/functional/recordings/test_bucket_and_object_crud/sts.py @@ -0,0 +1,34 @@ +# Recorded by smithy_test. Review it for anything identifying before committing. +from inspect import cleandoc + +from smithy_test import HTTPMockController + + +def install(controller: HTTPMockController) -> None: + ( + controller.expect_operation("GetCallerIdentity") + .times(1) + .respond_with( + status_code=200, + headers={ + "x-amzn-RequestId": "RECORDED-REQUEST-ID", + "X-Amz-Sts-Extended-Request-Id": "RECORDED-REQUEST-ID", + "Content-Type": "text/xml", + "Content-Length": "469", + }, + body=cleandoc( + r""" + + + arn:aws:sts::123456789012:assumed-role/Recor/recorded-sessionrecorded-sess + AROARECORDED000000001:recorded-sessionrecorded-sess + 123456789012 + + + 00000000-0000-4000-8000-000000000001 + + + """ + ), + ) + ) diff --git a/clients/aws-sdk-s3/tests/functional/test_recorded_crud.py b/clients/aws-sdk-s3/tests/functional/test_recorded_crud.py new file mode 100644 index 00000000..f8abdb96 --- /dev/null +++ b/clients/aws-sdk-s3/tests/functional/test_recorded_crud.py @@ -0,0 +1,88 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +"""Bucket and object CRUD, replayed from recordings of the live service. + +Record against AWS with ``SMITHY_PYTHON_TEST_MODE=record pytest ``. + +The recordings are in ``recordings//.py``. One recording serves +both clients, because playback answers by operation and never looks at the request. +Recording runs both clients, and the later run overwrites the recording. + +The bucket is in the account regional namespace, which only the account can create +buckets in, so nobody else can take the name. Its name contains the account ID, which +a recorded STS call provides, so the ID is never in the repository. +""" + +from contextlib import AsyncExitStack +from typing import cast +from uuid import uuid4 + +import pytest +from aws_sdk_s3.aio import AsyncS3Client, AsyncS3Config +from aws_sdk_s3.client import S3Client +from aws_sdk_s3.config import S3Config +from aws_sdk_sts.client import STSClient +from aws_sdk_sts.config import STSConfig +from dual_mode import MODES, AwaitableClient, Mode +from smithy_core.aio.utils import read_streaming_blob_async +from smithy_test import instrument +from smithy_test.aio import instrument_async + +REGION = "us-west-2" + + +@pytest.mark.parametrize("mode", MODES) +async def test_bucket_and_object_crud(mode: Mode) -> None: + sts = STSClient(STSConfig.resolve(region=REGION)) + with sts, instrument(sts): + account = sts.get_caller_identity().account + assert account + bucket = f"aws-sdk-python-recorded-{uuid4().hex[:8]}-{account}-{REGION}-an" + + async with AsyncExitStack() as stack: + if mode == "async": + client = AsyncS3Client(await AsyncS3Config.resolve(region=REGION)) + await stack.enter_async_context(client) + await stack.enter_async_context( + await instrument_async(client, redact=[account]) + ) + s3 = client + else: + sync = S3Client(S3Config.resolve(region=REGION)) + stack.enter_context(instrument(sync, redact=[account])) + adapter = await stack.enter_async_context(AwaitableClient(sync)) + s3 = cast(AsyncS3Client, adapter) + + await s3.create_bucket( + bucket=bucket, + create_bucket_configuration={"location_constraint": REGION}, + bucket_namespace="account-regional", + ) + try: + await s3.head_bucket(bucket=bucket) + + await s3.put_object( + bucket=bucket, key="a/1.txt", body=b"hello", metadata={"k": "v"} + ) + got = await s3.get_object(bucket=bucket, key="a/1.txt") + assert await read_streaming_blob_async(got.body) == b"hello" + assert got.metadata == {"k": "v"} + + head = await s3.head_object(bucket=bucket, key="a/1.txt") + assert head.content_length == 5 + + await s3.copy_object( + bucket=bucket, key="a/2.txt", copy_source=f"{bucket}/a/1.txt" + ) + listed = await s3.list_objects_v2(bucket=bucket, prefix="a/") + assert [o.key for o in listed.contents or []] == ["a/1.txt", "a/2.txt"] + + await s3.delete_objects( + bucket=bucket, + delete={"objects": [{"key": "a/1.txt"}, {"key": "a/2.txt"}]}, + ) + listed = await s3.list_objects_v2(bucket=bucket) + assert not listed.contents + finally: + await s3.delete_bucket(bucket=bucket) diff --git a/codegen/gen_client.py b/codegen/gen_client.py index bba85777..9b659052 100644 --- a/codegen/gen_client.py +++ b/codegen/gen_client.py @@ -50,6 +50,11 @@ "aws-sdk-transcribe-streaming": ["iam", "s3", "sts"], } +# Clients whose tests call another client of this repo, resolved from source. +CLIENTS_REQUIRING_CLIENTS = { + "aws-sdk-s3": ["aws-sdk-sts"], +} + # Shared test helpers, such as dual_mode, live in the repo-root tests/ folder. SHARED_TEST_PATH = ( ("[tool.pytest.ini_options]\n", 'pythonpath = ["../../tests"]'), @@ -290,6 +295,8 @@ def _install_client(slug: str) -> None: if name in CLIENTS_REQUIRING_BOTO3: services = ",".join(CLIENTS_REQUIRING_BOTO3[name]) _uv_add(dest, "test", ["boto3", f"types-boto3-lite[{services}]"]) + for dependency in CLIENTS_REQUIRING_CLIENTS.get(name, []): + _uv_add(dest, "test", ["--editable", f"../{dependency}"]) print(f"wrote {dest}")