Questions tagged with Amazon EventBridge

Content language: English

Sort by most recent

Browse through the questions and answers listed below or filter and sort to narrow down your results.

How to define API Gateway to Eventbridge integration?

I am building an API Gateway (v1) integration such that posts to a given endpoint should route the body of the POST to my custom eventbus in Eventbridge. I have created the gateway endpoints, event bus etc but I am struggling with the definition of the integration. I am doing this in Terraform, which basically wraps the AWS API for PutIntegration and I cannot seem to figure out the correct format of the request-parameters map required by AWS. since eventbus payloads have a specific structure, I assume I need to build the map to construct that payload. I also saw a post about needing a custom X-Amz-Target header as well. Are there any AWS documented examples of just how to build this integration & mapping? My attempts invariably lead to an error response along the lines of: *Error updating API Gateway Integration: BadRequestException: Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression specified: tagmodernization-dev-us-west-2-eventbus-information-reporting, Invalid mapping expression specified: integration.request.body.Entries[0].EventBusName]* mapping variations I have tried include: integration.request.body.EventBusName integration.request.body.Entries[0].EventBusName] EventBusName I realize I can achieve a similar goal using VTL with the request templates capability, but I am still unclear on the output format of the mapping anyway.
1
answers
0
votes
244
views
asked 5 months ago

Run a Lambda function for RDS using the DBInstanceIdentifier

Hello, I have been trying to automate stopping RDS instance using a Lambda Function when the number of connections made to the instances are low than 1. I have used an EventBridge that triggers the Lambda function when the Alarm created goes into In Alarm. From this, it stops all the RDS instances even those with connections. I understand that the issue is in the Lambda function since it loops through all instances and turns them off. I was inquiring if there is a way to pass the DBInstanceIdentifier of the instance in alarm state only to the lambda function for it to only shut down the instance in which the alarm is on. Below is the lambda code used. import boto3 import os target_db = None region = os.environ['AWS_REGION'] rds = boto3.client('rds', region_name=region) def get_tags_for_db(db): instance_arn = db['DBInstanceArn'] instance_tags = rds.list_tags_for_resource(ResourceName=instance_arn) return instance_tags['TagList'] def get_tags_for_db_cluster(db): instance_arn = db['DBClusterArn'] instance_tags = rds.list_tags_for_resource(ResourceName=instance_arn) return instance_tags['TagList'] def lambda_handler(event, context): dbs = rds.describe_db_instances() readReplica = [] for db in dbs['DBInstances']: readReplicaDB = db['ReadReplicaDBInstanceIdentifiers'] readReplica.extend(readReplicaDB) print("readReplica : " + str(readReplica)) for db in dbs['DBInstances']: db_id = db['DBInstanceIdentifier'] db_engine = db['Engine'] print('DB ID : ' + str(db_id)) db_tags = get_tags_for_db(db) print("All Tags : " + str(db_tags)) tag = next(iter(filter(lambda tag: tag['Key'] == 'AutoStop' and tag['Value'].lower() == 'true', db_tags)), None) print("AutoStop Tag : " + str(tag)) if db_engine not in ['aurora-mysql','aurora-postgresql']: if db_id not in readReplica and len(readReplica) == 0: if tag: target_db = db print("DB Details : " + str(target_db)) db_id = target_db['DBInstanceIdentifier'] db_status = target_db['DBInstanceStatus'] print("DB ID : " + str(db_id)) print("DB Status : " + str(db_status)) if db_status == "available": AutoStopping = rds.stop_db_instance(DBInstanceIdentifier=db_id) print("Stopping DB : " + str(db_id)) else: print("Database already stopped : " + str(db_id)) else: print("AutoStop Tag Key not set for Database to Stop...") else: print("Cannot stop or start a Read-Replica Database...") dbs = rds.describe_db_clusters() readReplica = [] for db in dbs['DBClusters']: readReplicaDB = db['ReadReplicaIdentifiers'] readReplica.extend(readReplicaDB) print("readReplica : " + str(readReplica)) for db in dbs['DBClusters']: db_id = db['DBClusterIdentifier'] db_engine = db['Engine'] print('DB ID : ' + str(db_id)) db_tags = get_tags_for_db_cluster(db) print("All Tags : " + str(db_tags)) tag = next(iter(filter(lambda tag: tag['Key'] == 'AutoStop' and tag['Value'].lower() == 'true', db_tags)), None) print("AutoStop Tag : " + str(tag)) if db_engine in ['aurora-mysql','aurora-postgresql']: if db_id not in readReplica and len(readReplica) == 0: if tag: target_db = db db_id = target_db['DBClusterIdentifier'] db_status = target_db['Status'] print("Cluster DB ID : " + str(db_id)) print("Cluster DB Status : " + str(db_status)) if db_status == "available": AutoStopping = rds.stop_db_cluster(DBClusterIdentifier=db_id) print("Stopping Cluster DB : " + str(db_id)) else: print("Cluster Database already stopped : " + str(db_id)) else: print("AutoStop Tag Key not set for Cluster Database to Stop...") else: print("Cannot stop or start a Read-Replica Cluster Database...")
2
answers
0
votes
178
views
asked 5 months ago

Unable to pass aws.events.event.json in input transformer template

I am using eventbridge to trigger batch run through custom put-events request(using boto3). My request is as follows :- ```python INPUT_DATA = { "data":[List<Dict>], # i.e. data key has list value where each list item is dict "sample_key":"sample_string_value" } client = boto3.client("events") response = client.put_events(Entries=[ { "Source": "my.app.com", "Detail": json.dumps(INPUT_DATA), "DetailType":"sample-type", "EventBusName":"my-event-bus" } ]) ``` In order to pass data from eventbridge to batch, I have following input transformer template :- ```terraform input_paths = { } input_template = <<EOF { "ContainerOverrides": { "Environment": [ { "Name": "PAYLOAD", "Value": "<aws.events.event.json>" } ] } } EOF ``` where `aws.events.event.json` is pre-defined variable for event payload(i.e. detail key value) as *string*. When I run the script, I am able to see metric for `triggeredRule`with `1` but invocation for batch run fails i.e. `failedInvocations` count as `1` is also seen in the metrics. At the same time, if replace `aws.events.event.json` with `aws.events.rule-arn` or `aws.events.rule-name` or `aws.events.event.ingestion-time`, batch run is triggered and correct values of latter variables is also seen in job descriptions's environment section. I tried to refer similar issue [here](https://repost.aws/questions/QUCMU-UIYoThyQqlkCn2sWEQ/eventbridge-input-transformer-example-doesnt-work) but it does not seem solve the issue. Can someone suggest where is the issue in above input transformer while using `aws.events.event.json` ? Is it due format of `INPUT_DATA` that I am sending ? Would appreciate any hint. Thanks
1
answers
0
votes
62
views
asked 6 months ago

How to use if-then-else and loop construct in input transformer in EventBridge?

Is there a way to define **if-then-else** and **looping** constructs using JSONPath, while defining the configuring the "input path" for EventBridge Input Transformer? E.g. For the following input ``` { "category": { "name": "Nike Shoes", "level": 2, "translation": null, "ancestors": { "edges": [ { "node": { "name": "Shoes", "slug": "shoes", "level": 0 } }, { "node": { "name": "Running Shoes", "slug": "running-shoes", "level": 1 } } ] } } } ``` I need the output to be ``` { "categories.lvl0": "Shoes", "categories.lvl1": "Shoes > Running shoes", "categories.lvl2": "Shoes > Running shoes > Nike shoes", } ``` The following is the python logic for the output I wish to achieve ```python if node["category"]["level"] != 0: category_hierarchy = list(map(lambda x: x["node"]["name"], node["category"]["ancestors"]["edges"])) category_hierarchy.append(new_item["categoryName"]) for i in range(len(category_hierarchy)): new_item[f'categories.lvl{i}'] = " > ".join(category_hierarchy[0:i+1]) ``` if the level of the main category ("Nike shoes" here) is not equal to 0, then I want to loop through its ancestors and define variables of the form `categories.lvl(n)` with the logic defined in column 2 below, to get the values defined in column 3 | Variable | Logic | Value required | | --------- | ------ | ------------------ | | category.lvl0 | ancestor category with level 0 | Shoes | | category.lvl1 | ancestor category with level 0 > ancestor category with level 1 | Shoes> Running shoes | | category.lvl2 | ancestor category with level 0 > ancestor category with level 1 > main category (with level 0) | Shoes> Running shoes > Nike shoes| I could frame the following JSONPath construct for now, which in plain English, represents: "if the category level is 0, then proceed to output names of the ancestor categories" JSONPath - `$..edges[?(@.level!=0)]..name` Output ``` [ "Shoes", "Running shoes" ] ``` However, I am not sure how to proceed further.
0
answers
0
votes
76
views
satvik
asked 6 months ago

No further functionality after "eventType": "INITIATED" message while implementing Amazon Connect high-volume outbound communications

I have just created Campaign in Connect with Contact flow, Then IAM policies, EventBridge and Pinpoint stuff with Creation of Segments & Journeys and in return i got the first event as "eventType": "INITIATED" with Type "VOICE". But then it stuck and nothing happen, it should dial a number using outbound queue as mention in the [Documentation](https://aws.amazon.com/blogs/contact-center/make-predictive-and-progressive-calls-using-amazon-connect-high-volume-outbound-communications/#:~:text=Under%20%E2%80%9COutbound%20call%20configuration%E2%80%9D%2C%20choose%20any%20phone%20number%20for,button%20at%20the%20top%2Dright.) as below: ``` { "version": "0", "id": "35af9eb2-5dda-fafc-48ce-78f223478a85", "detail-type": "Amazon Connect Contact Event", "source": "aws.connect", "account": "XXX92XXX3XXX", "time": "2022-05-31T08:21:52Z", "region": "us-east-1", "resources": [ "arn:aws:connect:us-east-1:XXX92XXX3XXX:instance/8XXXXXX9-1XXa-4XXf-bXXf-3XXXXXXXXX4", "arn:aws:connect:us-east-1:XXX92XXX3XXX:instance/8XXXXXX9-1XXa-4XXf-bXXf-3XXXXXXXXX4/contact/7b552ed3-b276-42ea-9837-31f8622f4fde" ], "detail": { "initiationTimestamp": "2022-05-31T08:21:52.769Z", "contactId": "7b552ed3-b276-42ea-9837-31f8622f4fde", "channel": "VOICE", "instanceArn": "arn:aws:connect:us-east-1:XXX92XXX3XXX:instance/8XXXXXX9-1XXa-4XXf-bXXf-3XXXXXXXXX4", "initiationMethod": "API", "eventType": "INITIATED", "campaign": { "campaignId": "8b00b16f-b083-4a00-ae86-58332f524b2b" } } } ``` In the end after the time ends it closed the journey with message "Message Not Sent". It should dial an outbound number at numbers added through segment and than return the events but somehow it doesn't working. In CSV segment file what format we have to used for phone number? e.g. General! when we add E.164 phone in CSV file and saved it, it throw an alert `"some features in your workbook might be lost if you save it as csv UTF-8 (comma delimited)"`. May be its changing the format.
1
answers
0
votes
57
views
asked 6 months ago