š§¾ Overview of Cost Considerations by Service
1. DynamoDB
- š”Ā On-demand vs provisioned:
- ProvisionedĀ is cheaper if access is predictable. UseĀ Auto ScalingĀ if uncertain.
- šĀ Avoid hot partitions: Distribute access evenly using good partition key design.
- ā³Ā Enable TTL (Time To Live): Automatically delete stale data.
- š¾Ā Use DAX or cachingĀ (e.g., with Amplify or Lambda) to reduce reads.
- š¦Ā Watch storage: Monitor size growth. Large payloads = large bills.
- š§¹Ā Clean up unused tablesĀ in non-prod environments.
2. AWS Amplify
- š”Ā Use only necessary Amplify features:
Hosting, auth, storage, GraphQL APIs can rack up costsādisable unused categories. - šøĀ Hosting costs scale with usage + storage.
Optimize asset size and invalidate old builds. - šĀ Avoid redeploying often, especially for small changes.
- šĀ Use environment-specific backends, but clean up unused ones.
3. Lambda
- ā±Ā Keep functions fast: Youāre billed for time * RAM.
- š¦Ā Minimize memory allocation: 128MB is cheap, 512MB+ adds up fast.
- š§ŖĀ Use Lambda Power TuningĀ to find optimal memory/runtime balance.
- ā ļøĀ Avoid recursive callsĀ or poorly terminated functions.
- š§¹Ā Delete unused versionsĀ andĀ clean up layers.
4. CloudFormation
- šĀ Free itself, but canĀ create cost-incurring resources.
- š Be careful with templates that create high-tier instances/services by default.
- š§¹Ā Remove old stacks/environmentsĀ in test/dev.
5. CloudWatch
- šĀ Logs and metrics cost money!Ā Especially retention.
- KeepĀ short log retentionĀ for dev/test (e.g., 3 days).
- SetĀ log filtersĀ selectively (donāt log everything).
- š§½ UseĀ
aws logs delete-log-groupĀ to clean up unused logs. - š” Consider exporting logs to S3 and deleting from CW if needed long-term.
6. API Gateway
- šøĀ REST APIs are more expensiveĀ than HTTP APIs.
- UseĀ HTTP APIsĀ when you donāt need advanced features (e.g. authorizers, WAF).
- š§Ŗ UseĀ usage plans + throttling + quotas.
- šĀ Enable cachingĀ to reduce Lambda invocations.
7. IAM
- š No direct cost, but indirect:
- EnsureĀ least privilege: Accidental access to high-cost resources can spike bills.
- Monitor role usage (some features are billable).
š General Recommendations
š 1. Set Budgets and Alerts
- UseĀ AWS BudgetsĀ andĀ Cost Anomaly Detection.
- EnableĀ notifications on spikesĀ in Lambda invocations, API calls, storage usage, etc.
š¦ 2. Tag All Resources
- Use cost allocation tags likeĀ
env,Āteam,Āproject. - Group by environment to isolate cost-heavy dev or test setups.
š 3. Minimize Environments
- Donāt keep too many dev/test environments running 24/7.
- Automate teardown and re-creation when possible.
š§ 4. Use Savings Plans or Reserved Instances
- If you have predictable Lambda/Compute usage.
š 5. Monitor with Cost Explorer
- Check cost per service, daily granularity.
- EnableĀ Resource-level tracking.
ā Pro Tips
| Goal | Strategy |
|---|---|
| Reduce Lambda cost | Optimize memory + runtime, use async when possible |
| Reduce API Gateway cost | Switch to HTTP APIs, enable caching, combine endpoints |
| Reduce DynamoDB cost | Provisioned capacity + Auto Scaling, optimize reads/writes |
| Reduce Amplify cost | Host only necessary features, minimize build frequency |
| Reduce CloudWatch cost | Shorten log retention, remove unnecessary metrics/logs |
| General cleanup | Automate stack/resource teardown in dev, especially Amplify environments |