def main(ledger_name=Constants.LEDGER_NAME_WITH_TAGS):
    """
    Tagging and un-tagging resources, including tag on create.
    """
    try:
        result = create_with_tags(ledger_name, CREATE_TAGS)
        wait_for_active(ledger_name)
        ARN = result.get('Arn')
        list_tags(ARN)
        untag_resource(ARN, REMOVE_TAGS)
        list_tags(ARN)
        tag_resource(ARN, ADD_TAGS)
        list_tags(ARN)
    except Exception as e:
        logger.exception('Unable to tag or untag resources!')
        raise e
Esempio n. 2
0
def main(ledger_name=LEDGER_NAME):
    """
    Demonstrate the protection of QLDB ledgers against deletion.
    """
    try:
        create_with_deletion_protection(ledger_name)
        wait_for_active(ledger_name)
        try:
            delete_ledger(ledger_name)
        except qldb_client.exceptions.ResourcePreconditionNotMetException:
            logger.info(
                'Ledger protected against deletions! Turning off deletion protection now.'
            )
        set_deletion_protection(ledger_name, False)
        delete_ledger(ledger_name)
    except Exception as e:
        logger.exception('Error while updating or deleting the ledger!')
        raise e

def create_with_deletion_protection(ledger_name):
    """
    Create a new ledger with the specified name and with deletion protection enabled.
    :type ledger_name: str
    :param ledger_name: Name for the ledger to be created.
    :rtype: dict
    :return: Result from the request.
    """
    logger.info("Let's create the ledger with name: {}...".format(ledger_name))
    result = qldb_client.create_ledger(Name=ledger_name, PermissionsMode='ALLOW_ALL')
    logger.info('Success. Ledger state: {}'.format(result.get('State')))
    return result


if __name__ == '__main__':
    """
    Demonstrate the protection of QLDB ledgers against deletion.
    """
    try:
        create_with_deletion_protection(LEDGER_NAME)
        wait_for_active(LEDGER_NAME)
        try:
            delete_ledger(LEDGER_NAME)
        except qldb_client.exceptions.ResourcePreconditionNotMetException:
            logger.info('Ledger protected against deletions! Turning off deletion protection now.')
        set_deletion_protection(LEDGER_NAME, False)
        delete_ledger(LEDGER_NAME)
    except Exception:
        logger.exception('Error while updating or deleting the ledger!')
Esempio n. 4
0
    Returns all tags for a specified Amazon QLDB resource.

    :type resource_arn: dict
    :param resource_arn: The Amazon Resource Name (ARN) for which to list tags off.

    :rtype: dict
    :return: All tags on the specified resource.
    """
    logger.info(
        "Let's list the tags for resource with arn: {}.".format(resource_arn))
    result = qldb_client.list_tags_for_resource(ResourceArn=resource_arn)
    logger.info('Success. Tags: {}.'.format(result.get('Tags')))
    return result


if __name__ == '__main__':
    """
    Tagging and un-tagging resources, including tag on create.
    """
    try:
        result = create_with_tags(Constants.LEDGER_NAME_WITH_TAGS, CREATE_TAGS)
        wait_for_active(Constants.LEDGER_NAME_WITH_TAGS)
        ARN = result.get('Arn')
        list_tags(ARN)
        untag_resource(ARN, REMOVE_TAGS)
        list_tags(ARN)
        tag_resource(ARN, ADD_TAGS)
        list_tags(ARN)
    except Exception:
        logger.exception('Unable to tag or untag resources!')