This is another Express + TypeScript + DDD (Domain Driven Design patterns) + IoC/DI (Inversion of control and Dependency injection) + API REST boilerplate.
Author: Gonzalo Plaza [email protected]
yarn install
cp .env.dist .env
You have to configure local environment variables with your own parameters inside .env file. These are the default values:
PORT=3000
APP_NAME="cognito-workshop"
APP_LOG_LEVEL="debug"
AWS_ACCESS_KEY_ID="your_aws_access_key_id"
AWS_SECRET_ACCESS_KEY="your_aws_secret_access_key"
COGNITO_USER_POOL="your_cognito_user_pool"
COGNITO_CLIENT_ID="your_cognito_client_id"
COGNITO_REGION="your-aws-region-x"
yarn dev
yarn test #In progress
yarn build
AWS Cognito is implemented as default authentication service. Please, check documentation on how to configure it for more details: https://aws.amazon.com/cognito/getting-started/
This project is ready to work with docker-compose 3.8 to initialize the needed stack during development process. To start working run the following commands:
docker-compose build
docker-compose up
To shut down local stack:
docker-compose down
curl http://localhost:8080/
Example JSON response (/):
{
"success": true,
"message": "Hello Cognito Workshop",
"timestamp": 1648208765884
}
You can build an optimized Docker production-ready image with the standard command:
docker build --no-cache -t cognito-workshop .
And then run the container passing environment variables within the initialization:
docker run --rm -it -p 3000:3000 \
-e NODE_ENV=production \
-e AWS_ACCESS_KEY_ID="your_aws_access_key_id" \
-e AWS_SECRET_ACCESS_KEY="your_aws_secret_access_key" \
-e COGNITO_USER_POOL="your_cognito_user_pool" \
-e COGNITO_CLIENT_ID="your_cognito_client_id" \
-e COGNITO_REGION="your-aws-region-x" \
-e APP_LOG_LEVEL="info" \
--name cognito-workshop cognito-workshop
In order to create/deploy the current stack to AWS using CloudFormation you'll need to generate your own .aws-envs file that you can copy from the provided template:
cp .aws-envs.example .aws-envs
Note: This process will need a proper role created into your AWS Account with enough permissions to create all needed resources, including IAM roles. You will need also to specify a working AWS VPC and 2 subnets. To execute it:
yarn deploy-stack # This is valid for stack create or update.
And to remove stack from cloudformation:
yarn remove-stack
- Decouple dependency on aws key and secret variables
- Link AWS LoadBalancer to Route53 domain and SSL certificate
- Add tests and coverage
- https://nathanpeck.com/speeding-up-amazon-ecs-container-deployments
- https://docs.aws.amazon.com/es_es/AWSCloudFormation/latest/UserGuide/AWS_ECS.html
- https://docs.aws.amazon.com/elasticloadbalancing/latest/application/target-group-health-checks.html
- https://docs.aws.amazon.com/es_es/AWSCloudFormation/latest/UserGuide/AWS_ElasticLoadBalancingV2.html
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-targetgroup.html
- https://github.com/aaronwht/aws-ecs-typescript