https://github.com/juhamust/bitbucket2sns
Serverless powered lambda function to convert Bitbucket webhook msgs into AWS SNS
https://github.com/juhamust/bitbucket2sns
aws-sns bitbucket lambda notifications serverless trigger webhook-requests
Last synced: 11 months ago
JSON representation
Serverless powered lambda function to convert Bitbucket webhook msgs into AWS SNS
- Host: GitHub
- URL: https://github.com/juhamust/bitbucket2sns
- Owner: juhamust
- License: mit
- Created: 2016-05-02T14:48:51.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-06-28T04:33:20.000Z (almost 9 years ago)
- Last Synced: 2025-04-05T17:11:11.516Z (about 1 year ago)
- Topics: aws-sns, bitbucket, lambda, notifications, serverless, trigger, webhook-requests
- Language: JavaScript
- Size: 235 KB
- Stars: 12
- Watchers: 4
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bitbucket2SNS
Bitbucket2SNS transforms Bitbucket webhook requests into [AWS SNS](https://aws.amazon.com/sns/) -notifications, making it easy to integrate with other AWS services, for example run [Lambda function](https://aws.amazon.com/lambda/) on every commit.

[](https://travis-ci.org/juhamust/bitbucket2sns)
### Deploy to AWS
Install recent Node (v6.10 preferred) and Serverless packages. Usage of `nvm` is encouraged.
```bash
# Install Node and Serverless
nvm use v6.10
npm install -g serverless@1.12
sls --version
# Clone and init codebase
git clone https://github.com/juhamust/bitbucket2sns.git
cd bitbucket2sns/
npm install
# Edit settings if needed
vim env.yml
# Deploy
sls deploy --profile=my-aws-profile
# Output (copy endpoint address)
> Service Information
> service: bitbucket2sns
> stage: dev
> region: eu-central-1
> api keys:
> None
> endpoints:
> POST - https://123123.execute-api.eu-central-1.amazonaws.com/dev/webhook
> functions:
> webhook: bitbucket2sns-dev-webhook
```
### Configure Bitbucket repository
1. Open Bitbucket repository (that you want to send webhook requests to AWS) settings
1. Open webhook -section in Bitbucket repository: Settings > Integrations > Webhooks
1. Click **Add webhook** and paste the collected URL **and** set the authentication token as `?token=` (usage of token is optional but recommended). Example: `https://123123.execute-api.eu-west-1.amazonaws.com/dev/webhook?token=secret`
1. You can test the functionality by committing a new change set. Bitbucket webhook requests can be reviewed after sending in **View requests**.

1. You can see the Lambda logs in [AWS CloudWatch](https://aws.amazon.com/cloudwatch/)
### Define lambda for SNS message (optional)
Once you've setup Bitbucket - SNS properly configured, you can start using it. Following snippet shows how to trigger a lambda on notification.
1. Go to Lambda -service
1. Start new Lambda with **Create a Lambda function**
1. Type in the code (see example)
1. Use `bitbucket-sns` as event source
1. See Monitoring section for lambda logs
```javascript
'use strict';
console.log('Loading function');
exports.handler = (event, context, callback) => {
const message = event.Records[0].Sns.Message;
console.log('From SNS:', message);
callback(null, message);
};
```

## Changelog
#### 0.2.0
- Support for Serverless 1.x
- Added unit testing
#### 0.1.0
- Initial release
## License
MIT -licensed