AWS document said we can make use of S3, lambda, etc. but still do not know how. this link mentioned some way but the link insides is invalid..... https://aws.amazon.com/blogs/devops/integrating-git-with-aws-codepipeline/
Asked
Active
Viewed 1.1k times
2 Answers
6
You can use this guide to set up a system so that your git repository is synchronized to an S3 bucket.

Matthew Sainsbury
- 1,470
- 3
- 18
- 42
-
Thanks! Now I have created the system using Cloudformartion. now when I git push, my gitlab does push event to lambda, however, somehow, the lambda could not download files from gitlab repository. lambda log showed "Downloading..." then timeout. – user389955 Apr 28 '18 at 00:55
-
if I wget that the gitlab link, I am redirected to a gitlab signin link and then get 404 response. looks like the link created in lambda is not enough, need to provide addition information to login? – user389955 Apr 28 '18 at 01:33
-
Thanks Mathew. after I set VPC part in lambda function, the system now work like expected, – user389955 Apr 30 '18 at 21:14
-
Matthew Sainsbury: do you know how to pass commit id of gitlab to codepipeline? right now codepipeline source part show S3 version id, which is nothing to do with gitlab commit id. in fact gitlab has passed commit_id and other info. to lambda function. I am thinking maybe I can let lambda pass the commit id and commit url to codepipeline so that I can put commit url in code review part of approval page and I can see commit id somewhere in codepipeline page? but I do not know how to do that yet. – user389955 May 02 '18 at 23:41
-
You would probably have to create a file as part of the source artifact you generate for code pipeline, containing the git metadata you want. However, I don't think Code Pipeline would be able to show you that information in the console. – Matthew Sainsbury May 03 '18 at 15:35
-
Thanks Matthew Sainsbury. this can be a workaround if no more choice. – user389955 May 03 '18 at 17:08
-
Matthew Sainsbury: seems you have good knowledge of making code pipeline work with gitlab. do you know how to trigger codepipeline only if code is push to master branch of gitlab? My codepipeline is triggered whenever code from any branch is pushed to gitlab. looks like gitlab always push event to AWS, and then the url received by Lambda at AWS does not show branch, and then Lambda at AWS just replaced .git to the master branch and download code to s3... I want to have either 1) gitlab only push event when master branch changes; 2) or lambda can figure out branch before download. any idea? Thx – user389955 Jun 28 '18 at 01:57
-
You could adjust the lambda function to figure out what branch the webhook call is for, and only download the source if it's the master branch. Here's an example of where the branch name is inspected in the message: https://github.com/aws-quickstart/quickstart-git2s3/blob/master/functions/source/GitPullS3/lambda_function.py#L172 – Matthew Sainsbury Jun 28 '18 at 18:38
-
Matthew Sainsbury: Thank you very much! I saw the branch info in gitlab push event request as well. the link you show is very useful! You know everything! – user389955 Jun 28 '18 at 22:38
-
Matthew Sainsbury: I manually made change in Lambda and it works like charm! Thank you! Do you know how to change the lambda by changing the cloud formation code provided by the link? git2s3.template is the only code I got from the link. the template said the lambda is not in this file but is grabbed from s3 "...packages/ZipDl/lambda.zip". I do see the file in s3...but it is also created by cloud formation. I guess I need to change the lambda somewhere and apply git2s3.template to cloud formation again and then the s3 bucket will have my updated lambda. But where to change the lambda? Thanks. – user389955 Jun 29 '18 at 01:12
-
Matthew Sainsbury: Besides, the current lambda name has some random letter. if I goto cloudformation console, then->check “Git-to-Amazon-S3”->Action->update stack->Update a template to Amazon S3->upload updated git2s3.template.will the lambda function be renamed with a new ramdom letter? then it will break the whole system. have not tried that. I know terraform but not cloud formation very well. – user389955 Jun 29 '18 at 01:16
4
You can mirror your Gitlab repository to AWS CodeCommit and use that mirrored repo as a source action for your pipeline. I think that's the easiest way of accomplishing it.
How to mirror from Gitlab to AWS CodeCommit.
How to use AWS CodeCommit as a source action for you pipeline.

Jels Boulangier
- 734
- 6
- 9
-
Thanks for providing the answer. the design requires that we use gitlab not CodeCommit so finally I did not use this way. – user389955 Oct 07 '20 at 06:12