Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(new-ex): add an Amplify Console App Example #59

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions typescript/amplify-console-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Amplify Console App
<!--BEGIN STABILITY BANNER-->
---

![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge)

> **This is an experimental example. It may not build out of the box**
>
> This examples does is built on Construct Libraries marked "Experimental" and may not be updated for latest breaking changes.
>
> It additionally requires infrastructure prerequisites that must be created before successful build.
>
> If build is unsuccessful, please create an [issue](https://github.com/aws-samples/aws-cdk-examples/issues/new) so that we may debug the problem

---
<!--END STABILITY BANNER-->

This an example of an Amplify Console App, triggering a build and deploy of a static site on every GitHub Repository master push.
This example requires a github repo containing a static website.

## Build

Before building this app, you must first edit `intex.ts` with information on your particular repo.

To build this app, you need to be in this example's root folder. Then run the following:

```bash
npm install -g aws-cdk
npm install
npm run build
```

This will install the necessary CDK, then this example's dependencies, and then build your TypeScript files and your CloudFormation template.

## Deploy

Run `cdk deploy`. This will deploy / redeploy your Stack to your AWS Account.

After the deployment you will see the API's URL, which represents the url you can then use.

## The Component Structure

This Stack contains:

- an Amplify Console App resource, representing the Amplify Console App that you wish to build and deploy, you need to specify its name, the URL of the GitHub Repository and the OAuth token from GitHub, which will authorize Amplify Console to access the repository and listen to commits.
- an Amplify Console Branch resource, representing the branch, to which whenever you push code it will trigger a build of your app.
3 changes: 3 additions & 0 deletions typescript/amplify-console-app/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app": "node index"
}
23 changes: 23 additions & 0 deletions typescript/amplify-console-app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import cdk = require('@aws-cdk/core');
import { CfnApp, CfnBranch } from '@aws-cdk/aws-amplify';

export class AmplifyConsoleAppCdkStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const amplifyApp = new CfnApp(this, 'test-app', {
name: 'your-amplify-console-app-name',
repository: 'https://github.com/<the-rest-of-the-repository-url>',
oauthToken: '<your-gitHub-oauth-token>'
});

new CfnBranch(this, 'MasterBranch', {
appId: amplifyApp.attrAppId,
branchName: 'master' // you can put any branch here (careful, it will listen to changes on this branch)
});
}
}

const app = new cdk.App();
new AmplifyConsoleAppCdkStack(app, 'AmplifyConsoleApp');
app.synth();
24 changes: 24 additions & 0 deletions typescript/amplify-console-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "appsync-graphql-dynamodb",
"version": "1.0.0",
"description": "Running an Amplify Console App static site from a GitHub repository, with a trigger on the master branch",
"private": true,
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"cdk": "cdk"
},
"author": {
"name": "Aleksandar Simovic <[email protected]>",
"url": "https://serverless.pub"
},
"license": "MIT",
"devDependencies": {
"@types/node": "^8.10.38",
"typescript": "~3.7.2"
},
"dependencies": {
"@aws-cdk/aws-amplify": "*",
"@aws-cdk/core": "*"
}
}
21 changes: 21 additions & 0 deletions typescript/amplify-console-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target":"ES2018",
"module": "commonjs",
"lib": ["es2016", "es2017.object", "es2017.string"],
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": false,
"inlineSourceMap": true,
"inlineSources": true,
"experimentalDecorators": true,
"strictPropertyInitialization":false
}
}