Skip to content

How can I extract a value from AWS Lambda event that's triggured from AWS Config

0

I'm referencing this blogpost below, and working on something similar https://aws.amazon.com/blogs/mt/tracking-and-remediating-non-compliant-resources-by-integrating-aws-config-and-atlassian-jira-service-management-through-automated-webhooks/

{ "version": "0", "id": "600ffa36-d38f-dcd6-8e17-bff3e72394c1", "detail-type": "Config Rules Compliance Change", "source": "aws.config", "account": "XXXXXXXXXXXX", "time": "2023-01-26T20:54:27Z", "region": "us-west-2", "resources": [], "detail": { "resourceId": "vol-0d47ce395abf3e14a", "awsRegion": "us-west-2", "awsAccountId": "XXXXXXXXXXXX", "configRuleName": "encrypted-volumes", "recordVersion": "1.0", "configRuleARN": "arn:aws:config:us-west-2:XXXXXXXXXXXX:config-rule/aws-service-rule/config-conforms.amazonaws.com/config-rule-09h0sc", "messageType": "ComplianceChangeNotification", "newEvaluationResult": { "evaluationResultIdentifier": { "evaluationResultQualifier": { "configRuleName": "encrypted-volumes", "resourceType": "AWS::EC2::Volume", "resourceId": "vol-0d47ce395abf3e14a", "evaluationMode": "DETECTIVE" }, "orderingTimestamp": "2023-01-26T20:53:57.118Z" }, "complianceType": "NON_COMPLIANT", "resultRecordedTime": "2023-01-26T20:54:26.943Z", "configRuleInvokedTime": "2023-01-26T20:54:26.797Z" }, "notificationCreationTime": "2023-01-26T20:54:27.320Z", "resourceType": "AWS::EC2::Volume" } }

Would I be able to extract it with this? I ask because many times in the event it's in a nested list. And I can directly extract the HTTP payload as for this reason.

ruleName = event['ruleName']

Are there any ways to test external services or anything event payload that Lambda receives to determine hwo to appropriately extract the key value pairs?

1 Answer
2
Accepted Answer

Hello.

There is no element called 'ruleName' in the json you are checking, so I think you need to get the rule name using the element 'configRuleName'.
Also, 'configRuleName' is an element included in 'detail', so it needs to be as follows.

ruleName = event['detail']['configRuleName']

If you want to test, you can check the operation by pasting the json you want to test in "Event JSON" from the test tab of the Lambda function and clicking "Test".
a

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

EXPERT

reviewed 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.