aws-quickstart / quickstart-git2s3

AWS Quick Start Team
Apache License 2.0
170 stars 114 forks source link

full_name': KeyError” in GitPullLambda when processing BitBucket WebHook request #27

Open sathyajackson opened 6 years ago

sathyajackson commented 6 years ago

Hi All,

I am facing the same problem as #14. We have an in-house bitbucket and trying to integrate the webhook with AWS service. While troubleshooting with AWS we found that the payload from the bitbucket is completely different from the one which the lambda function expects.

Lambda error : -

'project': KeyError Traceback (most recent call last): File "/var/task/lambda_function.py", line 158, in lambda_handler full_name = event['body-json']['project']['path_with_namespace'] KeyError: 'project'

Bitbucket body sent : -

{ "eventKey":"repo:refs_changed", "date":"2018-10-30T12:06:21+0000", "actor":{ "name":"sathyanarayanan.ramamurthy", "emailAddress":"Sathyanarayanan.Ramamurthy@csscorp.com", "id":269, "displayName":"Sathyanarayanan Ramamurthy", "active":true, "slug":"sathyanarayanan.ramamurthy", "type":"NORMAL" }, "repository":{ "slug":"demo-aws-codedeploy", "id":361, "name":"demo-aws-codedeploy", "scmId":"git", "state":"AVAILABLE", "statusMessage":"Available", "forkable":true, "project":{ "key":"IT", "id":154, "name":"Internal Testing", "public":false, "type":"NORMAL" }, "public":false }, "changes":[ { "ref":{ "id":"refs/heads/master", "displayId":"master", "type":"BRANCH" }, "refId":"refs/heads/master", "fromHash":"ebb01dc966228ea93cc6036d9efe94f56480b89d", "toHash":"3f8371baa548e516eee3d68b09fb4f608ff42920", "type":"UPDATE" } ] }

sathyajackson commented 6 years ago

any update would be of great help

sathyajackson commented 6 years ago

Any update?

sathyajackson commented 5 years ago

I Have no idea and how to fix the lambda code to support bitbucket server with aws code pipeline. Any suggestion or help with being much appreciated.

mfergus1 commented 5 years ago

I have this same issue @sathyajackson. The test payload will fail - but if you actually push to your repo, that payload will succeed.

mfergus1 commented 5 years ago

@sathyajackson If you still need to modify the lambda.zip, you can pull it down from github (https://github.com/aws-quickstart/quickstart-git2s3/blob/master/functions/packages/GitPullS3/lambda.zip), modify it, and push it back up to the generated zips s3 bucket and manually attach it to your lambda function (upload the modified lambda.zip)

chilprasanth commented 5 years ago

Hi Mia, I followed the steps you mentioned and uploaded the lamda.zip in zips s3 bucket and and in the lambda function , however I still get the following error 'project': KeyError Traceback (most recent call last): File "/var/task/lambda_function.py", line 158, in lambda_handler full_name = event['body-json']['project']['path_with_namespace'] KeyError: 'project'

I also noticed that in the lambda_fucntion under line 158 I dont have the following full_name = event['body-json']['project']['path_with_namespace'] but rather have the following in the code from the updated lambda.zip file try: full_name = event['body-json']['repository']['path_with_namespace'] So where is the error picking from (the line mentioned in error is actually at line 172 in the code)