# AWS Service 1 to AWS Service 2 This pattern allows you to validate your pull requests by running test on a Codebuild and post a comment on the specific PR. Learn more about this pattern at Serverless Land Patterns: << Add the live URL here >> Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example. ## Requirements * [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources. * [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured * [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) * ## Deployment Instructions 1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository: ```bash git clone https://github.com/aws-samples/serverless-patterns ``` 2. Change directory to the pattern directory: ```bash cd cdk-codecommit-codebuild ``` 2. Install node Packages: ```bash npm install ``` 3. Edit `./cdk/validator.ts` with your CodeCommit Repository name: ```typescript const staticSite = new PipelineStack(app, "codebuildOnPR", { repositoryName: "Your Repository Name", }); ``` 4. Make sure to have a `buildspec.yml` file is present in your CodeCommit repository: ```yaml version: 0.2 phases: build: commands: - echo 'test' artifacts: files: - '**/*' ``` **Make sure that the buildspec.yml is in the PR.** 5. From the command line, use AWS CDK to deploy the AWS resources for the pattern: ```bash npx cdk synth npx cdk deploy ``` ## How it works When you create (or update) a PullRequest an Event is published to AWS EventBridge. A Rule is configured in EventBridge to trigger a CodeBuild pointing on the source of your PullRequest. When the CodeBuild is finished (with Success OR Failure), an Event is published to AWS EventBridge. Two Rules are configured to trigger a Lambda that will comment on the Pull Request with the build Status. Everything is deployed using the CDK (except from the CodeCommit repository). You can find the Lambda Code in the directory `./src`. ## Testing 1. Create a CodeCommit repository with a buildspec.yml 2. Create a branch on CodeCommit 3. Create a Pull Request on your CodeCommit repository 4. Wait until the codebuild is finished 5. Check comments on your Pull Requests 6. Click on `see logs` to access your build result. ## Cleanup 1. Change directory to the pattern directory: ```bash cd cdk-codecommit-codebuild ``` 1. From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file: ```bash npx cdk destroy ``` ---- Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: MIT-0