Bitbucket webhook to AWS codeBuild - amazon-web-services

Recently AWS codebuild webhook supports PULL_REQUEST_MERGED event,which triggers the build every time a pull request is merged.
However we have to enable the merged event in Bitbucket webhook setting if we create a webhook filter group that uses the PULL_REQUEST_MERGED event type.
I am confused what should be the server URL of the AWS code build.
I read many tutorial but most of them are for integration of bitbucket with jenkins, not sure how to configure with AWS.

Thank you for using AWS CodeBuild. For Bitbucket webhook integration, you can check out this CodeBuild Bitbucket webhook sample in CodeBuild user guide.
Basically when you create a bitbucket webhook through CodeBuild console or calling CodeBuild's CreateWebhook API, CodeBuild will create the webhook and fill in the URL for you. You can also configure filter groups with PULL_REQUEST_MERGED event type on CodeBuild console.
After the webhook is created, you can check its settings on Bitbucket site. And you can edit which events will trigger Bitbucket to deliver a webhook payload.

Related

Trigger AWS CodePipeline to rebuild my app via webhook

How would I make a webhook (which I'll be using from my CMS) to invoke my CodePipeline?
I've got a simple CodePipeline setup that looks like this.
Source (Github) -> AWS CodeBuild -> AWS S3
It's a Node app that builds an application based on resources from a CMS.
At the moment only committing to the Github Repository invokes CodePipeline to remake my app.
However, I'm wanting a webhook or URL trigger to invoke the CodePipeline to recreate my app when certain changes in the CMS occur.
How do I create a webhook to invoke CodePipeline?
Not sure if it is the cleanest way. If you created an API Gateway that invokes a Lambda. In the lambda you could use one of the AWS sdks to run a script. For example, If you used Python, it would be the boto3.start_build()
That is just the first though I had.
Outside of a sdk or cli, I think Pipelines only work with ECR, S3, CodeCommit, BitBucket, and Github.

How can I trigger codebuild via webhook for pull request declined event from bitbucket?

I am using Bitbucket Cloud (bitbucket.org) as source control and codebuild as CI tool. I am able to trigger codebuild job from bitbucket via webhook but I can't find a way to trigger it if a PR is declined. When reading this article: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-webhookfilter.html, PULL_REQUEST_DECLINED event is not listed.
Below is my filter for webhook:
Triggers:
Webhook: true
FilterGroups:
- - Pattern: PUSH,PULL_REQUEST_CREATED,PULL_REQUEST_UPDATED,PULL_REQUEST_MERGED
Type: EVENT
If I add PULL_REQUEST_DECLINED there, cloudformation will return an error about unsupported filter event.
So how can I trigger it for PR declined event?
The reason I need to add declined event is that my codebuild deploys some resources to AWS when a PR is created, then there will be some integration tests are running. I'd like to remove all these resources when the PR is merged or declined.
First - just to make sure we're being clear, are you using Bitbucket Cloud (bitbucket.org) or Bitbucket Server?
From the documentation you linked, it looks like simply specifying a new expected EVENT pattern matching the payload you're getting from Bitbucket should be what you need.
In either case, I recommend looking over the full payload documentation for Bitbucket webhooks (assuming you're not using a third-party app or something) and use an attribute specific to that type of payload in creating the filter/listener in codebuild:
Bitbucket Cloud Event Payloads
Bitbucket Server Event Payloads
⚠️ Be sure to adjust top right dropdown to match your version number

Trigger Gitlab-ci from aws lambda

Im looking for lambda that can trigger Gitlab-ci pipeline to deploy specific branches and send results to slack.
Thx.
Trigger a pipeline
As per GitLab Trigger API manual:
To trigger a job you need to send a POST request to GitLab’s API endpoint:
curl -X POST <API url>/projects/<your_awesome_gitlab_project>/trigger/pipeline
The required parameters are the trigger’s token and the Git ref on which the trigger will be performed. Valid refs are the branch and the tag. The :id of a project can be found by querying the API or by visiting the CI/CD settings page which provides self-explanatory examples.
Watching a pipeline
To check pipeline results, use CloudWatch Events:
You can set up a rule to run an AWS Lambda function on a schedule. This tutorial shows how to use the AWS Management Console or the AWS CLI to create the rule. If you would like to use the AWS CLI but have not installed it, see the AWS Command Line Interface User Guide.
To check jobs status, use: Get a single pipeline or List project pipelines API calls.
curl --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/projects/1/pipelines/46"
Inform on Slack
To send Slack notifications with lambda, use this tutorial:
Creating an AWS Lambda Function and API Endpoint | Slack
Two cents about endpoint security
CI Trigger is secured by token. In general, it's enough for securing your endpoints.
But, if the approach isn't enough, there are some techniques to "hide" endpoints:
client IP whitelisting with GitLab
AWS Security Groups for Lambda or for EC2
Securing URLs with Nginx or with HAProxy

AWS console to github

I'd like to know if I can use my git repository for AWS console ? In fact i made a rails project on AWS console but I did not find as to how to transfer it on to my Github repository
You can use AWS Cloud and Github through
Custom Webhooks: Where you have your code store in github and serve through AWS services like EC2, Lambda, etc.
AWS Code Pipeline with Code Commit: The AWS code commit service can be configure to listen to github webhook requests, from there you can trigger events when the webhook is received e.g. Build, tests, deploy
Reference:

How to get BitBucket Server v5.15.1 (on-premise) webhook to trigger Lambda via API Gateway to get into S3?

I'm working with an on-premise older version of BitBucket Server v5.15.1 that does not have the Bitbucket Pipelines feature and I need how to get the webhooks to notify AWS Lambda via HTTPS POST via AWS API Gateway after a commit is made to master branch...then Lambda downloads a copy of the repo, zips it up and places it into an S3 bucket...and of course this is where CodePipeline can finally be triggered...But I'm having issues getting this on-premise BitBucket Server located within my AWS account to connect its webhook to Lambda.
I tried following this documentation below and launched the CloudFormation template with all the needed resources but I'm assuming it is for BitBucket Cloud not Bitbucket Server OP.
https://aws.amazon.com/blogs/devops/integrating-git-with-aws-codepipeline/
Anyones help with this would be really appreciated.
I suppose you are following this below blog from AWS :
https://aws.amazon.com/blogs/devops/integrating-codepipeline-with-on-premises-bitbucket-server/
We had also implemented it. If the event is coming to Lambda, then make sure your Lambda is within a VPC and it has correct outbound(read as inbound) rules to connect the Bitbucket server over HTTPS. Also the Bitbucket server accepts the VPC IP range.