carlin
v1.39.12
Published
**carlin** is a CLI tool for deploying AWS cloud resources using CloudFormation templates. It streamlines infrastructure deployment with automatic Lambda code building, S3 upload handling, stack naming, and multi-environment support.
Readme
carlin
carlin is a CLI tool for deploying AWS cloud resources using CloudFormation templates. It streamlines infrastructure deployment with automatic Lambda code building, S3 upload handling, stack naming, and multi-environment support.
Installation
pnpm add -D carlinOr install globally:
pnpm add -g carlinQuick Start
Deploy your CloudFormation template with a single command:
carlin deploycarlin automatically:
- Searches for your CloudFormation template (
cloudformation.ts,cloudformation.yml, ortemplate.yml) - Builds and uploads Lambda function code to S3
- Creates or updates your CloudFormation stack
- Displays stack outputs after deployment
First Deployment Example
Create a simple CloudFormation template:
// cloudformation.ts
export const template = {
Resources: {
MyBucket: {
Type: 'AWS::S3::Bucket',
Properties: {
BucketName: 'my-app-bucket',
},
},
},
Outputs: {
BucketName: {
Value: { Ref: 'MyBucket' },
},
},
};Deploy it:
carlin deployThat's it! carlin creates the stack and outputs the bucket name.
Core Concepts
Stack Naming
carlin automatically generates CloudFormation stack names based on:
- Package name from
package.json - Environment (staging, production) or branch name
- Custom
--stack-nameoption (overrides automatic naming)
Example stack names:
my-app-production(package:my-app, environment:production)my-app-feature-auth(package:my-app, branch:feature/auth)CustomStack(using--stack-name CustomStack)
Environments
Define environments using:
--environmentflag:carlin deploy --environment productionCARLIN_ENVIRONMENTvariable:CARLIN_ENVIRONMENT=staging carlin deploy- Config file:
carlin.ymlwithenvironment: production
Environments enable:
- Automatic termination protection for production stacks
- Environment-specific configurations
- Multi-stage deployment workflows
Lambda Functions
carlin automatically handles Lambda deployment:
- Detects Lambda functions in your CloudFormation template
- Builds code using esbuild
- Uploads to S3 with versioning
- Injects S3 parameters into your template
Example Lambda function:
// src/handler.ts
export const handler = async (event) => {
return { statusCode: 200, body: 'Hello World' };
};
// cloudformation.ts
export const template = {
Resources: {
MyFunction: {
Type: 'AWS::Lambda::Function',
Properties: {
Runtime: 'nodejs20.x',
Handler: 'handler.handler', // carlin finds and builds src/handler.ts
Code: {
S3Bucket: { Ref: 'LambdaS3Bucket' },
S3Key: { Ref: 'LambdaS3Key' },
S3ObjectVersion: { Ref: 'LambdaS3ObjectVersion' },
},
},
},
},
};Base Stack
The base stack provides shared infrastructure:
- S3 bucket for Lambda code storage
- CloudFront distribution for static apps
- Lambda image builder for container deployments
Deploy base stack once per environment:
carlin deploy base-stack --environment productionCommands
deploy
Deploy CloudFormation stacks and resources.
carlin deploy [options]Main Options
--template-path <path>- CloudFormation template file path--stack-name <name>- Custom stack name--parameters <json>- CloudFormation parameters as JSON object--environment <env>- Environment name (enables termination protection)--region <region>- AWS region (default:us-east-1)--destroy- Delete the stack instead of deploying
Subcommands
deploy static-app- Deploy static websites to S3 + CloudFrontdeploy lambda-layer- Deploy Lambda layersdeploy base-stack- Deploy base infrastructure stackdeploy cicd- Deploy CI/CD pipeline infrastructuredeploy vercel- Deploy to Vercel platformdeploy describe- Show stack outputs without deploying
See full command documentation for all options and examples.
generate-env
Generate .env files from CloudFormation stack outputs.
carlin generate-env --stack-name MyStack --output .envFetches stack outputs and creates environment variables file:
# Generated by carlin
API_URL=https://api.example.com
BUCKET_NAME=my-app-bucket-xyz123cicd-ecs-task-report
Report ECS task status to GitHub/Slack during CI/CD deployments.
carlin cicd-ecs-task-report --cluster my-cluster --task-arn <arn>Configuration
Configure carlin using CLI options, environment variables, or config files.
Config File
Create carlin.yml in your project root:
environment: staging
region: us-east-1
stackName: my-custom-stack
parameters:
DomainName: example.com
CertificateArn: arn:aws:acm:...Environment Variables
Prefix any option with CARLIN_:
CARLIN_ENVIRONMENT=production carlin deploy
CARLIN_REGION=eu-west-1 carlin deploy
CARLIN_STACK_NAME=CustomStack carlin deployPriority
Configuration priority (highest to lowest):
- CLI options (
--environment production) - Environment variables (
CARLIN_ENVIRONMENT=production) - Config file (
carlin.yml) - Defaults
Advanced Usage
Multi-Environment Deployment
Deploy to multiple environments with different configurations:
# Deploy to staging
carlin deploy --environment staging --parameters '{"InstanceType":"t3.micro"}'
# Deploy to production
carlin deploy --environment production --parameters '{"InstanceType":"t3.large"}'Custom Template Paths
Search for templates in custom locations:
carlin deploy --template-path infrastructure/cloudformation.tsDocker-Based Lambda Functions
Build Lambda functions from Dockerfiles:
carlin deploy --lambda-dockerfile Dockerfilecarlin automatically:
- Builds the Docker image
- Pushes to ECR
- Updates Lambda function with new image URI
Termination Protection
Production stacks are protected from accidental deletion:
# This fails if environment is defined
carlin deploy --destroy --environment production
# Force deletion by removing environment
carlin deploy --destroy --stack-name my-stack-productionBranch-Based Deployments
Deploy feature branches for testing:
# On feature/auth branch
carlin deploy
# Creates stack: my-app-feature-auth
# On main branch
carlin deploy --environment production
# Creates stack: my-app-productionTroubleshooting
Stack Already Exists
If deployment fails with "Stack already exists", check:
- Stack name conflicts (use
--stack-nameto customize) - Existing stacks in AWS Console (CloudFormation → Stacks)
- Branch name conflicts (different branches may create same stack name)
Lambda Build Failures
If Lambda code building fails:
- Verify
Handlerpath points to existing file (src/handler.ts) - Check
--lambda-entry-points-base-dirmatches your source directory - Review build logs for missing dependencies
Template Too Large
CloudFormation templates over 51,200 bytes must be uploaded to S3:
- carlin automatically uploads large templates to base stack bucket
- Ensure base stack exists:
carlin deploy base-stack - Or reduce template size by removing comments/whitespace
Permission Errors
Ensure AWS credentials have necessary permissions:
cloudformation:*for stack operationss3:*for Lambda code uploadsiam:*for creating roleslambda:*for function deployments
Examples
Documentation
Full documentation: https://ttoss.dev/docs/carlin/
License
MIT © Pedro Arantes
