in templates/custom-resources/lex-manager.py [0:0]
def add_prefix(bot_definition, prefix='WebUi'):
""" Adds a prefix to resource names in a bot definition
Used to differentiate bots from the same definition file in CloudFormation
when running multiple stacks in the same region and to make policy easier
"""
bot = bot_definition['bot']
bot['name'] = prefix + bot['name']
bot['intents'] = list(map(
lambda intent: dict(
intentName=(prefix + intent.pop('intentName')),
**intent
),
bot_definition['bot']['intents']
))
slot_types = list(map(
lambda slot_type: dict(
name=(prefix + slot_type.pop('name')),
**slot_type
),
bot_definition['slot_types']
))
intents = map(
lambda intent: dict(
name=(prefix + intent.pop('name')),
slots=list(map(
lambda slot: dict(
slotType=(prefix + slot.pop('slotType')),
**slot
) if (prefix + slot['slotType']) in [s['name'] for s in slot_types]
else slot,
intent.pop('slots')
)),
**intent
),
bot_definition['intents']
)
return dict(
bot=bot,
intents=list(intents),
slot_types=slot_types
)