} ) aws_lambda = lambda_.Function( f"{MODULE_NAME}", role=role.arn, runtime="python3.8", handler="lambda_handler.destinations", s3_key=config.require("artifact_name"), s3_bucket="morgue-artifacts", timeout=200, tracing_config={"mode": "Active"}, environment={"variables": lambda_variables}, layers=[dependency_layer.arn], # source_code_hash=filebase64sha256(f"build/{config.require('artifact_name')}") ) lambda_.EventSourceMapping( f"{MODULE_NAME}-dynamodb-esm", event_source_arn=dynamodb_table.stream_arn, function_name=aws_lambda.name, starting_position="LATEST", ) lambda_.EventSourceMapping( f"{MODULE_NAME}-kinesis-very-cool-esm", event_source_arn=error_stream.arn, function_name=aws_lambda.name, starting_position="LATEST", )
def __init__(self): resource_specs = ParseYAML(resource_type).getSpecs() for lambda_name, config in resource_specs.items(): config = config if config else {} resource_name = lambda_name resource_tags = config.get("tags") resource_env = config.get("environment") # Getting list of tags from configuration file tags_list = {} if resource_tags is not None: for each_tag_name, each_tag_value in resource_tags.items(): tags_list.update({each_tag_name: each_tag_value}) # Generating ENV vars env_list = {} if resource_env is not None: for each_env_name, each_env_value in resource_env.items(): env_list.update({each_env_name: each_env_value}) # Adding mandatory tags tags_list.update({"Name": resource_name}) tags_list.update({ "Project/Stack": pulumi.get_project() + "/" + pulumi.get_stack() }) tags_list.update(resource_mandatory_tags) lambda_function = lambda_.Function( lambda_name, environment=lambda_.FunctionEnvironmentArgs( variables=env_list), handler=config.get("handler"), s3_bucket=config.get("s3_bucket"), s3_key=config.get("s3_key"), s3_object_version=config.get("s3_object_version"), memory_size=config.get("memory_size"), publish=config.get("publish"), reserved_concurrent_executions=config.get( "reserved_concurrent_executions"), role=IAM.RoleARN()[config.get("role")], runtime=config.get("runtime"), timeout=config.get("timeout"), tags=tags_list) # Export pulumi.export(lambda_function._name, lambda_function.id) # Event source mappings for mapping_name, mapping_config in config.get( "event_source_mapping").items(): event_source = mapping_config["event_source"] assert event_source.get( "type" ) == "sqs", "Just sqs is currently supported as event source mapping. You're welcome to implement more." source_arn = SQS.ByName()[event_source["name"]].arn mapping = lambda_.EventSourceMapping( mapping_name, event_source_arn=source_arn, function_name=lambda_function.arn, batch_size=mapping_config.get("batch_size")) pulumi.export(mapping_name, mapping.id) lambdas_by_name[lambda_name] = lambda_function
"ReplicationLambdaAllowDynamoPolicy", role=lambdaRole.name, policy=getAllowDynamoStreamPolicyDocument( dynamoTable.stream_arn).apply(lambda d: json.dumps(d))) lambdaRoleAllowFirehosePutPolicy = iam.RolePolicy( "ReplicationLambdaAllowFirehosePolicy", role=lambdaRole.name, policy=getAllowFirehosePutPolicyDocument( deliveryStream.arn).apply(lambda d: json.dumps(d))) dynamoTriggerFunction = lambda_.Function( 'ReplicationLambdaFunction', role=lambdaRole.arn, runtime='python3.7', handler='dynamoTriggerLambda.handler', code=pulumi.FileArchive("./dynamoTriggerLambda"), environment={"Variables": { "DELIVERY_STREAM_NAME": deliveryStream.name }}) dynamoTrigger = lambda_.EventSourceMapping( "ReplicationDynamoTriggerMapping", event_source_arn=dynamoTable.stream_arn, function_name=dynamoTriggerFunction.arn, starting_position='LATEST') pulumi.export('table_name', dynamoTable.name) pulumi.export('bucket_name', bucket.id) pulumi.export('delivery_stream_name', deliveryStream.name)
role=role.id, ) aws_lambda = lambda_.Function( f"{MODULE_NAME}", role=role.arn, runtime="python3.6", handler="lambda_handler.twitch_chat_bot", s3_key=config.require("artifact_name"), s3_bucket="morgue-artifacts", tracing_config={"mode": "Active"}, timeout=200, layers=[dependency_layer.arn], environment={ "variables": { "CHARACTER_DB": dynamodb_table.name, "MORGUE_BUCKETNAME": bucket.id, "MORGUEBOT_TWITCH_OAUTH_TOKEN": twitch_oauth_token.ciphertext_blob, "MORGUEBOT_BOT_NAME": "beginbotbot", "MORGUEBOT_CHANNEL": "beginbot", } }, ) lambda_.EventSourceMapping( f"{MODULE_NAME}-kinesis-very-cool-esm", event_source_arn=chat_stream.arn, function_name=aws_lambda.name, starting_position="LATEST", )