Lambda Function Extra Character
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 \"
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
Relevant questions
i use this Lambda function to generate thumbnails on the fly. But i get the
Accepted Answerasked 3 years agoHow do I restrict AWS secret by Lambda alias?
Accepted Answerasked 3 months agoHow to remove member accounts from Organizations?
asked 4 months agoHow do you make 2FA work on both an AWS account and an Amazon consumer account?
asked 3 months agoAWS step function giving error, when I had included the "Parameter" tag
asked a month agohow do i delete a lambda@edge that isn't attached to a cloudfront?
asked 7 months agoHow can I pass a required field from my ipad application to Amazon Lex?
Accepted Answerasked 2 years agoLambda Function Extra Character
asked 19 days agoCan't connect to an RDS Instance from Lambda (different account tough)
asked 2 years agoHow do I use a schema fields default value in a template?
asked 3 years ago