MCPcopy Create free account
hub / github.com/awsdocs/aws-doc-sdk-examples / usage_demo

Function usage_demo

python/example_code/sts/assume_role_mfa.py:256–282  ·  view source on GitHub ↗

Drives the demonstration.

()

Source from the content-addressed store, hash-verified

254
255# snippet-start:[python.example_code.sts.Scenario_AssumeRoleMfa_demo]
256def usage_demo():
257 """Drives the demonstration."""
258 print("-" * 88)
259 print(
260 f"Welcome to the AWS Security Token Service assume role demo, "
261 f"starring multi-factor authentication (MFA)!"
262 )
263 print("-" * 88)
264 iam_resource = boto3.resource("iam")
265 user, user_key, virtual_mfa_device, role = setup(iam_resource)
266 print(f"Created {user.name} and {role.name}.")
267 try:
268 sts_client = boto3.client(
269 "sts", aws_access_key_id=user_key.id, aws_secret_access_key=user_key.secret
270 )
271 try_to_assume_role_without_mfa(role.arn, "demo-sts-session", sts_client)
272 mfa_totp = input("Enter the code from your registered MFA device: ")
273 list_buckets_from_assumed_role_with_mfa(
274 role.arn,
275 "demo-sts-session",
276 virtual_mfa_device.serial_number,
277 mfa_totp,
278 sts_client,
279 )
280 finally:
281 teardown(user, virtual_mfa_device, role)
282 print("Thanks for watching!")
283
284
285# snippet-end:[python.example_code.sts.Scenario_AssumeRoleMfa_demo]

Callers 1

assume_role_mfa.pyFile · 0.70

Calls 4

setupFunction · 0.70
teardownFunction · 0.70

Tested by

no test coverage detected