[docs]defbootstrap(bsm:BotoSesManager,aws_region:str,bucket_name:str,dynamodb_table_name:str,dynamodb_write_capacity_units:T.Optional[int]=None,dynamodb_read_capacity_units:T.Optional[int]=None,):""" Bootstrap the associated AWS account and region in the boto session manager. Create the S3 bucket and DynamoDB table if not exist. """# validate input argumentsifsum([dynamodb_write_capacity_unitsisNone,dynamodb_read_capacity_unitsisNone,])notin[0,2,]:# pragma: no coverraiseValueError# create s3 buckettry:bsm.s3_client.head_bucket(Bucket=bucket_name)exceptExceptionase:# pragma: no coverif"Not Found"instr(e):bsm.s3_client.create_bucket(Bucket=bucket_name)else:raisee# create dynamodb tableifdynamodb_write_capacity_unitsisNoneanddynamodb_read_capacity_unitsisNone:classBase(dynamodb.Base):classMeta:table_name=dynamodb_table_nameregion=aws_regionbilling_mode=PAY_PER_REQUEST_BILLING_MODEelse:# pragma: no coverclassBase(dynamodb.Base):classMeta:table_name=dynamodb_table_nameregion=aws_regionwrite_capacity_units=dynamodb_write_capacity_unitsread_capacity_units=dynamodb_read_capacity_units# bind s3pathlib to use the given boto sessioncontext.attach_boto_session(bsm.boto_ses)# bind pynamodb to use the given boto sessionwithuse_boto_session(Base,bsm,restore_on_exit=False,):Base.create_table(wait=True)