Lambda Function Extra Character

0

I am trying to use account = event['detail']['userIdentity']['accountId'] but the output of this looks like "account": "\"123456789012\"" how do I remove the leading and trailing \"

asked 2 years ago197 views
1 Answer
0

Is it possible for you to share the event you are using to test?

I used the below event to test:

{ "detail": { "eventVersion": "1.05", "userIdentity": { "type": "IAMUser", "principalId": "AIDAJDPLRKLG7UEXAMPLE", "arn": "arn:aws:iam::123456789012:user/Mary_Major", "accountId": "123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Mary_Major", "sessionContext": { "sessionIssuer": {}, "webIdFederationData": {}, "attributes": { "mfaAuthenticated": "false", "creationDate": "2019-06-18T22:28:31Z" } }, "invokedBy": "signin.amazonaws.com" }, "eventTime": "2019-06-19T00:18:31Z", "eventSource": "cloudtrail.amazonaws.com", "eventName": "StartLogging", "awsRegion": "us-east-2", "sourceIPAddress": "203.0.113.64", "userAgent": "signin.amazonaws.com", "requestParameters": { "name": "arn:aws:cloudtrail:us-east-2:123456789012:trail/My-First-Trail" }, "responseElements": null, "requestID": "ddf5140f-EXAMPLE", "eventID": "7116c6a1-EXAMPLE", "readOnly": false, "eventType": "AwsApiCall", "recipientAccountId": "123456789012" }, "someotherfield": "foo", "yetanotherfield": "bar" }

And my code is: print('$$$$$$$$$$$$$$$$$') body = event['detail']['userIdentity']['accountId'] print(body) print('$$$$$$$$$$$$$$$$$')

And the response I got from the lambda is Function Logs START RequestId: 3263d9d6-e0f0-4378-ae7e-f3c100883bd6 Version: $LATEST $$$$$$$$$$$$$$$$$ 123456789012 $$$$$$$$$$$$$$$$$ END RequestId: 3263d9d6-e0f0-4378-ae7e-f3c100883bd6

profile pictureAWS
EXPERT
answered 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.

Guidelines for Answering Questions