I want to mirror my Bitbucket repository to CodeCommit and build from it, without affecting developer's workflow. Migration is easy, now the goal is to sync CodeCommit with Bitbucket, ideally, triggered by pushing to Bitbucket, but time-based sync is also acceptable.
I found this post: https://aws.amazon.com/blogs/devops/replicating-and-automating-sync-ups-for-a-repository-with-aws-codecommit/ and unanswered question here Mirror a Git Repo directly to AWS CodeCommit
Please, share you ideas how to write aws lambda function to sync CodeCommit repository with Bitbucket.
To create a trigger for a Lambda functionOpen the CodeCommit console at https://console.aws.amazon.com/codesuite/codecommit/home . In Repositories, choose the repository where you want to create triggers for repository events. In the navigation pane for the repository, choose Settings, and then choose Triggers.
To connect to a CodeCommit repositoryOpen the CodeCommit console at https://console.aws.amazon.com/codesuite/codecommit/home . In the region selector, choose the AWS Region where the repository was created. Repositories are specific to an AWS Region. For more information, see Regions and Git connection endpoints.
To change a CodeCommit repository's nameRun the update-repository-name command, specifying: The current name of the CodeCommit repository (with the --old-name option). To get the CodeCommit repository's name, run the list-repositories command. The new name of the CodeCommit repository (with the --new-name option).
While I haven't tried this, I suspect the following workflow could work. The general idea would be to use the BitBucket webhooks feature to trigger the lambda function through the use of API gateway.
Write a Lambda function which 'mirror' clones from your bitbucket repository url and pushes to your CodeCommit repository url. Your function would likely need to include its own standalone git client library.
Create an API using API gateway which calls your lambda function. Potential challenges here might be verifying that POST requests going to your API are coming from Bitbucket, and not some other source.
Create a new webhook for your Bitbucket repository with the URL being the url of your API you created in step 2. A 'Repository push' trigger would be sufficient to trigger a replication event after each push.
One option is to use CodePipeline. Unfortunately with CodePipeline there is currently a weird process in making a Lambda function work as the sole process for the pipeline. Basically it comes down to:
Another option is to use CloudWatch scheduling to invoke the Lambda at X interval if you're okay with a more delayed sync. This will probably be easier to setup in the long run, with the possibility of having null Lambda runs if there's nothing to sync, counting against your allocation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With