Why AWS SAM, Not Serverless Framework?
We migrated five projects from Serverless Framework to AWS SAM and saw benefits every time: fewer workarounds, transparent CloudFormation stack, native integration with CDK. SAM is not just another abstraction layer — it's the official AWS tool, fully compatible with CloudFormation: the output is a full stack that can be versioned and rolled back. Instead of 50 lines of CloudFormation for Lambda + API Gateway + IAM Role, you write 10 lines of SAM. This reduces backend development time by 40% and lowers the risk of configuration errors. A typical SAM project costs 30–50% less than the Serverless Framework equivalent, thanks to less code and no plugins.
Our AWS-certified engineers have 5 years of experience in serverless architectures and have delivered over 30 SAM projects. We guarantee compatibility with your stack and cost optimization — for example, using Graviton2 saves up to 20% on Lambda, and infrastructure costs drop by 40% when migrating from EC2 to Lambda. As AWS states: "SAM is the easiest way to build serverless applications".
Why Graviton2?
AWS Graviton2 processors based on ARM64 architecture provide up to 20% better price performance compared to x86. SAM lets you choose the architecture in the template with a single line.Comparison: SAM vs. Serverless Framework
| Criterion | AWS SAM | Serverless Framework |
|---|---|---|
| Abstraction | Direct CloudFormation extension | Custom syntax with providers |
| Template size | 10 lines for a simple function | 15–20 lines with plugins |
| AWS integration | Native, full service support | Plugins required for some services |
| Local development | SAM CLI + Docker | serverless-offline |
| Stack versioning | CloudFormation Change Sets | Separate tools |
How to Set Up CI/CD for SAM?
Continuous integration and delivery are mandatory in any production architecture. SAM integrates seamlessly with popular pipelines: GitHub Actions, GitLab CI, AWS CodePipeline. A typical scenario: on push to the main branch, it runs sam build and deploys to the prod environment with automatic approval of Change Sets.
# .github/workflows/deploy.yml (fragment)
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/GitHubActions
aws-region: eu-west-1
- name: SAM build and deploy
run: |
sam build
sam deploy --no-confirm-changeset --no-fail-on-empty-changeset
For multi-environment configuration, use samconfig.toml with different profiles. Rollback is done via the standard CloudFormation rollback-stack command — zero downtime.
What Is Included in SAM Backend Setup?
Our work covers the full cycle: from auditing your current architecture to delivering documentation.
- Architecture document: service diagram, Lambda runtime selection, memory and timeout calculations.
- template.yaml: all resources (Lambda, API Gateway, DynamoDB, SQS, S3) with policies and environment variables.
- Lambda source code: handlers in TypeScript/Node.js 20, JWT authorizer, middlewares, tests.
- Configuration of environments: dev/staging/prod with different stages, SSM parameters for secrets.
- CI/CD pipeline: ready-to-use workflow for GitHub Actions or GitLab CI.
- Documentation and training: README with example calls, variable descriptions, developer instructions.
- Guarantee: one week of post-deployment support to fix any incidents.
Quick Start: Installation and Structure
brew tap aws/tap
brew install aws-sam-cli
# or: pip install aws-sam-cli
sam --version # SAM CLI, version 1.x
sam init --runtime nodejs20.x --dependency-manager npm --app-template hello-world --name my-backend
Project structure:
-
template.yaml— SAM template -
samconfig.toml— deployment config -
src/handlers/— handlers (api.ts, auth.ts, worker.ts) -
src/shared/— shared code (db.ts, response.ts) -
events/— test events -
__tests__/— tests
Template and Handler Configuration
Key elements of template.yaml:
AWSTemplateFormatVersion: '2010-09-31'
Transform: AWS::Serverless-2016-10-31
Description: My Web Backend
Globals:
Function:
Runtime: nodejs20.x
Architectures: [arm64]
MemorySize: 512
Timeout: 10
Api:
Cors:
AllowMethods: "'*'"
Resources:
ApiGateway:
Type: AWS::Serverless::HttpApi
Properties:
StageName: !Ref Stage
Auth:
DefaultAuthorizer: LambdaAuthorizer
Authorizers:
LambdaAuthorizer:
FunctionArn: !GetAtt AuthFunction.Arn
ApiFunction:
Type: AWS::Serverless::Function
Properties:
Handler: src/handlers/api.handler
Events:
AnyRoute:
Type: HttpApi
Properties:
ApiId: !Ref ApiGateway
Method: ANY
Path: /api/{proxy+}
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref MainTable
Metadata:
BuildMethod: esbuild
BuildProperties:
Minify: true
Target: es2022
Example Lambda Authorizer:
import { verify } from 'jsonwebtoken';
export const handler = async (event) => {
const token = event.headers?.authorization?.replace('Bearer ', '');
if (!token) return { isAuthorized: false };
try {
const payload = verify(token, process.env.JWT_SECRET!);
return { isAuthorized: true, context: { userId: String(payload.sub) } };
} catch {
return { isAuthorized: false };
}
};
How to Optimize SAM Costs?
- Use Graviton2 (arm64) — save up to 20% on Lambda.
- Set Provisioned Concurrency only for critical functions.
- Configure CloudWatch Lambda Insights to monitor and identify inefficient requests.
- Move static assets to S3 + CloudFront, don't overload API Gateway.
- Optimize deployment package size: esbuild minification, tree-shaking.
Local Development and CI/CD
For local execution, we use sam local start-api with a mocked DynamoDB via Docker. Environment configuration is set in samconfig.toml:
[default.deploy.parameters]
stack_name = "my-backend-dev"
s3_bucket = "artifacts-bucket"
region = "eu-west-1"
parameter_overrides = "Stage=dev"
Deployment is done with:
sam build && sam deploy --config-env dev
# or for prod
sam build && sam deploy --config-env prod
The process includes building (esbuild minification), generating Change Set, and applying. Rollback uses the standard CloudFormation rollback-stack command.
Process and Timelines
| Stage | Duration | Result |
|---|---|---|
| Architecture analysis | 0.5–1 day | Document with recommendations |
| SAM template design | 1–2 days | template.yaml, samconfig.toml |
| Lambda function implementation | 2–3 days | handlers, shared layer, tests |
| Integration with services | 1–2 days | DynamoDB, SQS, S3, API Gateway |
| Testing and debugging | 1–2 days | Unit and integration tests |
| Deployment and CI/CD | 1 day | Pipeline (GitHub Actions / GitLab CI) |
| Documentation and training | 0.5 day | README, example calls |
A basic SAM backend with one Lambda and DynamoDB — 1–2 days. A full architecture with an authorizer, background workers, and multiple environments — 4–5 days. Adapting existing Express/Fastify code — 3–5 days.
Contact us to evaluate your project — our engineers will analyze your current architecture and prepare a commercial proposal. Order turnkey AWS SAM setup — we'll handle all the infrastructure, from templates to CI/CD.







