Ann application based on Serverless framework utilizing AWS Lamda, API Gateway and Cognito services.
The installation process creates VPC, S3 bucket, Cognito User Pool, RDS instance,
Cloudfront distribution, Lambda functions and API Gateway. All resources are
prefixed with SERVICE_NAME variable. Please ensure that the prefix is unique,
if resources with same identifiers already exist, the installation will fail.
The application can be installed only to AWS region supporting all required services. You should be safe to install in regions: Northern Virginia, Oregon and Ireland.
- Install Serverless:
npm install -g serverless/serverless - Install AWS CLI (e.g.
pip install awsclion Mac) - Install Yarn (see https://yarnpkg.com/en/docs/install)
- Download git repository:
git clone [email protected]:keboola/developer-portal.git - Cd into directory:
cd developer-portal - Install dependencies:
yarn install - Setup Slack channel for notifications about users and apps approval requirements and create incoming webhook
- Either save AWS credentials to
~/.aws/credentials(see http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-multiple-profiles) or set env variablesAWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYprior to running following commands - Verify email sender. Run
node scripts/setup.js register-email <region> <email>and confirm link from the email you get - Run setup script:
env SERVICE_NAME= REGION= KEBOOLA_STACK= RDS_PASSWORD= RDS_INSTANCE_CLASS= SES_EMAIL_FROM= STAGE= LOG_HOST= LOG_PORT= SLACK_HOOK_URL= make install
- The script will put created identifiers to file
.env - Required env variables:
SERVICE_NAME- Name of the Serverless service. It will be used as a prefix for created AWS services, it should be only alphanumeric with optional dashesREGION- AWS region where the services should be createdKEBOOLA_STACK- KeboolaStack identifier likemartin-developer-portalRDS_PASSWORD- Desired password for created databaseRDS_INSTANCE_CLASS- Desired instance class of created RDS, see http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.DBInstanceClass.html butdb.t2.microshould work fineSES_EMAIL_FROM- Email address used as a sender for emailsSTAGE- Stage of the service (dev,testorprod)LOG_HOST- Papertrail endpoint hostnameLOG_PORT- Papertrail endpoint portSLACK_HOOK_URL- Slack webhook url for notifications
- Save generated
.envto a safe place
Please note that your SES service must be out of sandbox or you have to verify each email or domain before you use it for account signup.
You can connect to database using SSH tunel, use BASTION_IP from .env as SSH host and ec2-user as SSH user.
You can set created user as admin using command: node scripts/setup-admin.js <email> enable
- Look to
.envforAPI_ENDPOINTand create user. Confirm email and enable user in Cognito console - Run
env FUNC_USER_EMAIL=<userEmail> FUNC_USER_PASSWORD=<userPass> FUNC_VENDOR=<vendorId> mocha --timeout 0 test/functional
- Install according to steps 1-5 in the Installation section
- Get the
.envfile saved from installation and put it to the directory - Run
sls deploy
- Install according to steps 1-5 in the Installation section
- Get the
.envfile saved from installation and put it to the directory - Run
make removeto remove all resources from AWS
Whole configuration is held in .env which contains these parameters:
SERVICE_NAME=dev-portal
KEBOOLA_STACK=dev-portal
REGION=eu-west-1
STAGE=dev
[email protected]
RDS_INSTANCE_CLASS=db.t2.micro
RDS_DATABASE=devportal
RDS_USER=devportal
RDS_PASSWORD=dbpass
S3_BUCKET=dev-portal-resources
LOG_HOST=logs.papertrailapp.com
LOG_PORT=33333
SLACK_HOOK_URL='https://hooks.slack.com/services/...'
ACCOUNT_ID='061240556736'
VPC_CF_STACK_ID='arn:aws:cloudformation:eu-west-1:061240556736:stack/dev-portal-vpc/...'
VPC_SECURITY_GROUP=sg-d8b9d5be
RDS_SECURITY_GROUP=sg-d8b9d5be
VPC_SUBNET1=subnet-b05f7ac6
VPC_SUBNET2=subnet-b84360dc
RDS_SUBNET_GROUP=dev-portal-vpc-devportaldbsubnetgroup
COGNITO_POOL_ID=eu-west-1_xxx
COGNITO_CLIENT_ID=24q0k67ocvs9t56961gahjgd64
RDS_HOST=dev-portal-rds.cptjrpubo0om.eu-west-1.rds.amazonaws.com
RDS_PORT=3306
CLOUDFRONT_URI=dttajxboh9b9k.cloudfront.net
API_ENDPOINT='https://1puon0n5y2.execute-api.eu-west-1.amazonaws.com/dev'
PROFILE=dev
WARMUP_ENABLED=true
If you change variable WARMUP_ENABLED in .env to true, a CloudWatch schedule will be enabled to keep lambda functions for public resources warmed up using 15 minutes ping.
- Migrations are performed automatically after the deployment in a lambda function. So they have to be executed in a release previous to the one where the udpates are used.
- To prepare a migration create a
.jsfile in/migrationsdir. Its name consists of a timestamp and short description, i.e.yyyymmddhhiiss-description.js(e.g.20170526092800-deprecated-app.js). Copy its content from a previous one. Then put.sqlfile with the same name to/migrations/sqlswith the migrations themselves.
CI is configured on Travis, see https://travis-ci.org/keboola/developer-portal. Deployment is run automatically after releasing a version on GitHub. Travis uses special AWS IAM user with restricted rights in production account. See iam-user-template.json for details.