@ruaruababa/vibe-kit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CATALOG.md +317 -0
- package/README.md +121 -0
- package/aliases.json +65 -0
- package/bin/vibe.js +2 -0
- package/bundles.json +265 -0
- package/catalog.json +1560 -0
- package/dist/antigravity-skills/bin/cli.js +438 -0
- package/dist/antigravity-skills/lib/skill-utils.js +158 -0
- package/dist/antigravity-skills/scripts/build-catalog.js +305 -0
- package/dist/antigravity-skills/scripts/normalize-frontmatter.js +144 -0
- package/dist/antigravity-skills/scripts/validate-skills.js +230 -0
- package/dist/bin/vibe.js +2 -0
- package/dist/dist/src/cli/index.js +26 -0
- package/dist/lib/skill-utils.js +158 -0
- package/dist/scripts/build-catalog.js +50 -0
- package/dist/scripts/normalize-frontmatter.js +144 -0
- package/dist/scripts/validate-skills.js +56 -0
- package/dist/src/cli/index.js +146 -0
- package/dist/src/types/index.js +13 -0
- package/dist/src/utils/fs.js +1 -0
- package/package.json +43 -0
- package/skills/accessibility-compliance-accessibility-audit/SKILL.md +42 -0
- package/skills/accessibility-compliance-accessibility-audit/resources/implementation-playbook.md +502 -0
- package/skills/agent-orchestration-improve-agent/SKILL.md +349 -0
- package/skills/agent-orchestration-multi-agent-optimize/SKILL.md +239 -0
- package/skills/agent-orchestrator/SKILL.md +24 -0
- package/skills/ai-engineer/SKILL.md +171 -0
- package/skills/airflow-dag-patterns/SKILL.md +41 -0
- package/skills/airflow-dag-patterns/resources/implementation-playbook.md +509 -0
- package/skills/angular-migration/SKILL.md +428 -0
- package/skills/anti-reversing-techniques/SKILL.md +42 -0
- package/skills/anti-reversing-techniques/resources/implementation-playbook.md +539 -0
- package/skills/api-design-principles/SKILL.md +37 -0
- package/skills/api-design-principles/assets/api-design-checklist.md +155 -0
- package/skills/api-design-principles/assets/rest-api-template.py +182 -0
- package/skills/api-design-principles/references/graphql-schema-design.md +583 -0
- package/skills/api-design-principles/references/rest-best-practices.md +408 -0
- package/skills/api-design-principles/resources/implementation-playbook.md +513 -0
- package/skills/api-documenter/SKILL.md +184 -0
- package/skills/api-testing-observability-api-mock/SKILL.md +46 -0
- package/skills/api-testing-observability-api-mock/resources/implementation-playbook.md +1327 -0
- package/skills/application-performance-performance-optimization/SKILL.md +154 -0
- package/skills/architect-review/SKILL.md +174 -0
- package/skills/architecture-decision-records/SKILL.md +441 -0
- package/skills/architecture-patterns/SKILL.md +37 -0
- package/skills/architecture-patterns/resources/implementation-playbook.md +479 -0
- package/skills/arm-cortex-expert/SKILL.md +306 -0
- package/skills/async-python-patterns/SKILL.md +39 -0
- package/skills/async-python-patterns/resources/implementation-playbook.md +678 -0
- package/skills/attack-tree-construction/SKILL.md +38 -0
- package/skills/attack-tree-construction/resources/implementation-playbook.md +671 -0
- package/skills/auth-implementation-patterns/SKILL.md +39 -0
- package/skills/auth-implementation-patterns/resources/implementation-playbook.md +618 -0
- package/skills/backend-architect/SKILL.md +333 -0
- package/skills/backend-development-feature-development/SKILL.md +180 -0
- package/skills/backend-security-coder/SKILL.md +156 -0
- package/skills/backtesting-frameworks/SKILL.md +39 -0
- package/skills/backtesting-frameworks/resources/implementation-playbook.md +647 -0
- package/skills/bash-defensive-patterns/SKILL.md +43 -0
- package/skills/bash-defensive-patterns/resources/implementation-playbook.md +517 -0
- package/skills/bash-pro/SKILL.md +310 -0
- package/skills/bats-testing-patterns/SKILL.md +34 -0
- package/skills/bats-testing-patterns/resources/implementation-playbook.md +614 -0
- package/skills/bazel-build-optimization/SKILL.md +397 -0
- package/skills/billing-automation/SKILL.md +42 -0
- package/skills/billing-automation/resources/implementation-playbook.md +544 -0
- package/skills/binary-analysis-patterns/SKILL.md +450 -0
- package/skills/blockchain-developer/SKILL.md +208 -0
- package/skills/business-analyst/SKILL.md +182 -0
- package/skills/c-pro/SKILL.md +56 -0
- package/skills/c4-architecture-c4-architecture/SKILL.md +389 -0
- package/skills/c4-code/SKILL.md +244 -0
- package/skills/c4-component/SKILL.md +153 -0
- package/skills/c4-container/SKILL.md +171 -0
- package/skills/c4-context/SKILL.md +150 -0
- package/skills/changelog-automation/SKILL.md +38 -0
- package/skills/changelog-automation/resources/implementation-playbook.md +538 -0
- package/skills/cicd-automation-workflow-automate/SKILL.md +51 -0
- package/skills/cicd-automation-workflow-automate/resources/implementation-playbook.md +1333 -0
- package/skills/clean-markdown/SKILL.md +23 -0
- package/skills/cloud-architect/SKILL.md +135 -0
- package/skills/code-documentation-code-explain/SKILL.md +46 -0
- package/skills/code-documentation-code-explain/resources/implementation-playbook.md +802 -0
- package/skills/code-documentation-doc-generate/SKILL.md +48 -0
- package/skills/code-documentation-doc-generate/resources/implementation-playbook.md +640 -0
- package/skills/code-refactoring-context-restore/SKILL.md +179 -0
- package/skills/code-refactoring-refactor-clean/SKILL.md +51 -0
- package/skills/code-refactoring-refactor-clean/resources/implementation-playbook.md +879 -0
- package/skills/code-refactoring-tech-debt/SKILL.md +386 -0
- package/skills/code-review-ai-ai-review/SKILL.md +450 -0
- package/skills/code-review-excellence/SKILL.md +40 -0
- package/skills/code-review-excellence/resources/implementation-playbook.md +515 -0
- package/skills/code-reviewer/SKILL.md +178 -0
- package/skills/codebase-cleanup-deps-audit/SKILL.md +51 -0
- package/skills/codebase-cleanup-deps-audit/resources/implementation-playbook.md +766 -0
- package/skills/codebase-cleanup-refactor-clean/SKILL.md +51 -0
- package/skills/codebase-cleanup-refactor-clean/resources/implementation-playbook.md +879 -0
- package/skills/codebase-cleanup-tech-debt/SKILL.md +386 -0
- package/skills/competitive-landscape/SKILL.md +34 -0
- package/skills/competitive-landscape/resources/implementation-playbook.md +494 -0
- package/skills/comprehensive-review-full-review/SKILL.md +146 -0
- package/skills/comprehensive-review-pr-enhance/SKILL.md +46 -0
- package/skills/comprehensive-review-pr-enhance/resources/implementation-playbook.md +691 -0
- package/skills/conductor-implement/SKILL.md +388 -0
- package/skills/conductor-manage/SKILL.md +39 -0
- package/skills/conductor-manage/resources/implementation-playbook.md +1120 -0
- package/skills/conductor-new-track/SKILL.md +433 -0
- package/skills/conductor-revert/SKILL.md +372 -0
- package/skills/conductor-setup/SKILL.md +426 -0
- package/skills/conductor-status/SKILL.md +338 -0
- package/skills/conductor-validator/SKILL.md +62 -0
- package/skills/content-marketer/SKILL.md +170 -0
- package/skills/context-driven-development/SKILL.md +400 -0
- package/skills/context-management-context-restore/SKILL.md +179 -0
- package/skills/context-management-context-save/SKILL.md +177 -0
- package/skills/context-manager/SKILL.md +185 -0
- package/skills/cost-optimization/SKILL.md +286 -0
- package/skills/cpp-pro/SKILL.md +59 -0
- package/skills/cqrs-implementation/SKILL.md +35 -0
- package/skills/cqrs-implementation/resources/implementation-playbook.md +540 -0
- package/skills/csharp-pro/SKILL.md +59 -0
- package/skills/customer-support/SKILL.md +170 -0
- package/skills/data-engineer/SKILL.md +224 -0
- package/skills/data-engineering-data-driven-feature/SKILL.md +182 -0
- package/skills/data-engineering-data-pipeline/SKILL.md +201 -0
- package/skills/data-quality-frameworks/SKILL.md +40 -0
- package/skills/data-quality-frameworks/resources/implementation-playbook.md +573 -0
- package/skills/data-scientist/SKILL.md +199 -0
- package/skills/data-storytelling/SKILL.md +465 -0
- package/skills/database-admin/SKILL.md +165 -0
- package/skills/database-architect/SKILL.md +268 -0
- package/skills/database-cloud-optimization-cost-optimize/SKILL.md +44 -0
- package/skills/database-cloud-optimization-cost-optimize/resources/implementation-playbook.md +1441 -0
- package/skills/database-migration/SKILL.md +436 -0
- package/skills/database-migrations-migration-observability/SKILL.md +420 -0
- package/skills/database-migrations-sql-migrations/SKILL.md +53 -0
- package/skills/database-migrations-sql-migrations/resources/implementation-playbook.md +499 -0
- package/skills/database-optimizer/SKILL.md +167 -0
- package/skills/dbt-transformation-patterns/SKILL.md +34 -0
- package/skills/dbt-transformation-patterns/resources/implementation-playbook.md +547 -0
- package/skills/debugger/SKILL.md +49 -0
- package/skills/debugging-strategies/SKILL.md +34 -0
- package/skills/debugging-strategies/resources/implementation-playbook.md +511 -0
- package/skills/debugging-toolkit-smart-debug/SKILL.md +197 -0
- package/skills/defi-protocol-templates/SKILL.md +466 -0
- package/skills/dependency-management-deps-audit/SKILL.md +44 -0
- package/skills/dependency-management-deps-audit/resources/implementation-playbook.md +766 -0
- package/skills/dependency-upgrade/SKILL.md +421 -0
- package/skills/deployment-engineer/SKILL.md +170 -0
- package/skills/deployment-pipeline-design/SKILL.md +371 -0
- package/skills/deployment-validation-config-validate/SKILL.md +496 -0
- package/skills/devops-troubleshooter/SKILL.md +161 -0
- package/skills/distributed-debugging-debug-trace/SKILL.md +44 -0
- package/skills/distributed-debugging-debug-trace/resources/implementation-playbook.md +1307 -0
- package/skills/distributed-tracing/SKILL.md +450 -0
- package/skills/django-pro/SKILL.md +180 -0
- package/skills/docs-architect/SKILL.md +98 -0
- package/skills/documentation-generation-doc-generate/SKILL.md +48 -0
- package/skills/documentation-generation-doc-generate/resources/implementation-playbook.md +640 -0
- package/skills/dotnet-architect/SKILL.md +197 -0
- package/skills/dotnet-backend-patterns/SKILL.md +37 -0
- package/skills/dotnet-backend-patterns/assets/repository-template.cs +523 -0
- package/skills/dotnet-backend-patterns/assets/service-template.cs +336 -0
- package/skills/dotnet-backend-patterns/references/dapper-patterns.md +544 -0
- package/skills/dotnet-backend-patterns/references/ef-core-best-practices.md +355 -0
- package/skills/dotnet-backend-patterns/resources/implementation-playbook.md +799 -0
- package/skills/dummy-skill/SKILL.md +5 -0
- package/skills/dx-optimizer/SKILL.md +83 -0
- package/skills/e2e-testing-patterns/SKILL.md +41 -0
- package/skills/e2e-testing-patterns/resources/implementation-playbook.md +531 -0
- package/skills/elixir-pro/SKILL.md +59 -0
- package/skills/embedding-strategies/SKILL.md +491 -0
- package/skills/employment-contract-templates/SKILL.md +39 -0
- package/skills/employment-contract-templates/resources/implementation-playbook.md +493 -0
- package/skills/error-debugging-error-analysis/SKILL.md +47 -0
- package/skills/error-debugging-error-analysis/resources/implementation-playbook.md +1143 -0
- package/skills/error-debugging-error-trace/SKILL.md +43 -0
- package/skills/error-debugging-error-trace/resources/implementation-playbook.md +1361 -0
- package/skills/error-debugging-multi-agent-review/SKILL.md +216 -0
- package/skills/error-detective/SKILL.md +53 -0
- package/skills/error-diagnostics-error-analysis/SKILL.md +47 -0
- package/skills/error-diagnostics-error-analysis/resources/implementation-playbook.md +1143 -0
- package/skills/error-diagnostics-error-trace/SKILL.md +48 -0
- package/skills/error-diagnostics-error-trace/resources/implementation-playbook.md +1371 -0
- package/skills/error-diagnostics-smart-debug/SKILL.md +197 -0
- package/skills/error-handling-patterns/SKILL.md +35 -0
- package/skills/error-handling-patterns/resources/implementation-playbook.md +635 -0
- package/skills/event-sourcing-architect/SKILL.md +58 -0
- package/skills/event-store-design/SKILL.md +449 -0
- package/skills/fastapi-pro/SKILL.md +192 -0
- package/skills/fastapi-templates/SKILL.md +32 -0
- package/skills/fastapi-templates/resources/implementation-playbook.md +566 -0
- package/skills/final-test/SKILL.md +5 -0
- package/skills/firmware-analyst/SKILL.md +320 -0
- package/skills/flutter-expert/SKILL.md +200 -0
- package/skills/framework-migration-code-migrate/SKILL.md +48 -0
- package/skills/framework-migration-code-migrate/resources/implementation-playbook.md +1052 -0
- package/skills/framework-migration-deps-upgrade/SKILL.md +48 -0
- package/skills/framework-migration-deps-upgrade/resources/implementation-playbook.md +755 -0
- package/skills/framework-migration-legacy-modernize/SKILL.md +132 -0
- package/skills/frontend-developer/SKILL.md +171 -0
- package/skills/frontend-mobile-development-component-scaffold/SKILL.md +403 -0
- package/skills/frontend-mobile-security-xss-scan/SKILL.md +322 -0
- package/skills/frontend-security-coder/SKILL.md +170 -0
- package/skills/full-stack-orchestration-full-stack-feature/SKILL.md +135 -0
- package/skills/gdpr-data-handling/SKILL.md +33 -0
- package/skills/gdpr-data-handling/resources/implementation-playbook.md +615 -0
- package/skills/git-advanced-workflows/SKILL.md +412 -0
- package/skills/git-pr-workflows-git-workflow/SKILL.md +140 -0
- package/skills/git-pr-workflows-onboard/SKILL.md +416 -0
- package/skills/git-pr-workflows-pr-enhance/SKILL.md +48 -0
- package/skills/git-pr-workflows-pr-enhance/resources/implementation-playbook.md +701 -0
- package/skills/github-actions-templates/SKILL.md +345 -0
- package/skills/gitlab-ci-patterns/SKILL.md +283 -0
- package/skills/gitops-workflow/SKILL.md +303 -0
- package/skills/gitops-workflow/references/argocd-setup.md +134 -0
- package/skills/gitops-workflow/references/sync-policies.md +131 -0
- package/skills/go-concurrency-patterns/SKILL.md +33 -0
- package/skills/go-concurrency-patterns/resources/implementation-playbook.md +654 -0
- package/skills/godot-gdscript-patterns/SKILL.md +33 -0
- package/skills/godot-gdscript-patterns/resources/implementation-playbook.md +804 -0
- package/skills/golang-pro/SKILL.md +179 -0
- package/skills/grafana-dashboards/SKILL.md +381 -0
- package/skills/graphql-architect/SKILL.md +182 -0
- package/skills/haskell-pro/SKILL.md +56 -0
- package/skills/helm-chart-scaffolding/SKILL.md +34 -0
- package/skills/helm-chart-scaffolding/assets/Chart.yaml.template +42 -0
- package/skills/helm-chart-scaffolding/assets/values.yaml.template +185 -0
- package/skills/helm-chart-scaffolding/references/chart-structure.md +500 -0
- package/skills/helm-chart-scaffolding/resources/implementation-playbook.md +543 -0
- package/skills/helm-chart-scaffolding/scripts/validate-chart.sh +244 -0
- package/skills/hr-pro/SKILL.md +126 -0
- package/skills/hybrid-cloud-architect/SKILL.md +168 -0
- package/skills/hybrid-cloud-networking/SKILL.md +238 -0
- package/skills/hybrid-search-implementation/SKILL.md +32 -0
- package/skills/hybrid-search-implementation/resources/implementation-playbook.md +567 -0
- package/skills/incident-responder/SKILL.md +213 -0
- package/skills/incident-response-incident-response/SKILL.md +168 -0
- package/skills/incident-response-smart-fix/SKILL.md +29 -0
- package/skills/incident-response-smart-fix/resources/implementation-playbook.md +838 -0
- package/skills/incident-runbook-templates/SKILL.md +395 -0
- package/skills/ios-developer/SKILL.md +219 -0
- package/skills/istio-traffic-management/SKILL.md +337 -0
- package/skills/java-pro/SKILL.md +177 -0
- package/skills/javascript-pro/SKILL.md +57 -0
- package/skills/javascript-testing-patterns/SKILL.md +35 -0
- package/skills/javascript-testing-patterns/resources/implementation-playbook.md +1024 -0
- package/skills/javascript-typescript-typescript-scaffold/SKILL.md +361 -0
- package/skills/julia-pro/SKILL.md +209 -0
- package/skills/k8s-manifest-generator/SKILL.md +35 -0
- package/skills/k8s-manifest-generator/assets/configmap-template.yaml +296 -0
- package/skills/k8s-manifest-generator/assets/deployment-template.yaml +203 -0
- package/skills/k8s-manifest-generator/assets/service-template.yaml +171 -0
- package/skills/k8s-manifest-generator/references/deployment-spec.md +753 -0
- package/skills/k8s-manifest-generator/references/service-spec.md +724 -0
- package/skills/k8s-manifest-generator/resources/implementation-playbook.md +510 -0
- package/skills/k8s-security-policies/SKILL.md +346 -0
- package/skills/k8s-security-policies/assets/network-policy-template.yaml +177 -0
- package/skills/k8s-security-policies/references/rbac-patterns.md +187 -0
- package/skills/kpi-dashboard-design/SKILL.md +440 -0
- package/skills/kubernetes-architect/SKILL.md +170 -0
- package/skills/langchain-architecture/SKILL.md +350 -0
- package/skills/legacy-modernizer/SKILL.md +53 -0
- package/skills/legal-advisor/SKILL.md +70 -0
- package/skills/linkerd-patterns/SKILL.md +321 -0
- package/skills/llm-application-dev-ai-assistant/SKILL.md +35 -0
- package/skills/llm-application-dev-ai-assistant/resources/implementation-playbook.md +1236 -0
- package/skills/llm-application-dev-langchain-agent/SKILL.md +246 -0
- package/skills/llm-application-dev-prompt-optimize/SKILL.md +37 -0
- package/skills/llm-application-dev-prompt-optimize/resources/implementation-playbook.md +591 -0
- package/skills/llm-evaluation/SKILL.md +483 -0
- package/skills/machine-learning-ops-ml-pipeline/SKILL.md +314 -0
- package/skills/malware-analyst/SKILL.md +247 -0
- package/skills/market-sizing-analysis/SKILL.md +425 -0
- package/skills/market-sizing-analysis/examples/saas-market-sizing.md +349 -0
- package/skills/market-sizing-analysis/references/data-sources.md +360 -0
- package/skills/memory-forensics/SKILL.md +491 -0
- package/skills/memory-safety-patterns/SKILL.md +33 -0
- package/skills/memory-safety-patterns/resources/implementation-playbook.md +603 -0
- package/skills/mermaid-expert/SKILL.md +59 -0
- package/skills/microservices-patterns/SKILL.md +35 -0
- package/skills/microservices-patterns/resources/implementation-playbook.md +607 -0
- package/skills/minecraft-bukkit-pro/SKILL.md +126 -0
- package/skills/ml-engineer/SKILL.md +168 -0
- package/skills/ml-pipeline-workflow/SKILL.md +257 -0
- package/skills/mlops-engineer/SKILL.md +219 -0
- package/skills/mobile-developer/SKILL.md +205 -0
- package/skills/mobile-security-coder/SKILL.md +184 -0
- package/skills/modern-javascript-patterns/SKILL.md +35 -0
- package/skills/modern-javascript-patterns/resources/implementation-playbook.md +910 -0
- package/skills/monorepo-architect/SKILL.md +61 -0
- package/skills/monorepo-management/SKILL.md +35 -0
- package/skills/monorepo-management/resources/implementation-playbook.md +621 -0
- package/skills/mtls-configuration/SKILL.md +359 -0
- package/skills/multi-cloud-architecture/SKILL.md +189 -0
- package/skills/multi-platform-apps-multi-platform/SKILL.md +203 -0
- package/skills/network-engineer/SKILL.md +169 -0
- package/skills/nextjs-app-router-patterns/SKILL.md +33 -0
- package/skills/nextjs-app-router-patterns/resources/implementation-playbook.md +543 -0
- package/skills/nft-standards/SKILL.md +395 -0
- package/skills/node-expert/SKILL.md +23 -0
- package/skills/nodejs-backend-patterns/SKILL.md +35 -0
- package/skills/nodejs-backend-patterns/resources/implementation-playbook.md +1019 -0
- package/skills/nx-workspace-patterns/SKILL.md +464 -0
- package/skills/observability-engineer/SKILL.md +237 -0
- package/skills/observability-monitoring-monitor-setup/SKILL.md +48 -0
- package/skills/observability-monitoring-monitor-setup/resources/implementation-playbook.md +505 -0
- package/skills/observability-monitoring-slo-implement/SKILL.md +43 -0
- package/skills/observability-monitoring-slo-implement/resources/implementation-playbook.md +1077 -0
- package/skills/on-call-handoff-patterns/SKILL.md +453 -0
- package/skills/openapi-spec-generation/SKILL.md +33 -0
- package/skills/openapi-spec-generation/resources/implementation-playbook.md +1027 -0
- package/skills/payment-integration/SKILL.md +77 -0
- package/skills/paypal-integration/SKILL.md +479 -0
- package/skills/pci-compliance/SKILL.md +478 -0
- package/skills/performance-engineer/SKILL.md +180 -0
- package/skills/performance-testing-review-ai-review/SKILL.md +450 -0
- package/skills/performance-testing-review-multi-agent-review/SKILL.md +216 -0
- package/skills/php-pro/SKILL.md +63 -0
- package/skills/posix-shell-pro/SKILL.md +304 -0
- package/skills/postgresql/SKILL.md +230 -0
- package/skills/postmortem-writing/SKILL.md +386 -0
- package/skills/projection-patterns/SKILL.md +33 -0
- package/skills/projection-patterns/resources/implementation-playbook.md +501 -0
- package/skills/prometheus-configuration/SKILL.md +404 -0
- package/skills/prompt-engineer/SKILL.md +272 -0
- package/skills/prompt-engineering-patterns/SKILL.md +213 -0
- package/skills/prompt-engineering-patterns/assets/few-shot-examples.json +106 -0
- package/skills/prompt-engineering-patterns/assets/prompt-template-library.md +246 -0
- package/skills/prompt-engineering-patterns/references/chain-of-thought.md +399 -0
- package/skills/prompt-engineering-patterns/references/few-shot-learning.md +369 -0
- package/skills/prompt-engineering-patterns/references/prompt-optimization.md +414 -0
- package/skills/prompt-engineering-patterns/references/prompt-templates.md +470 -0
- package/skills/prompt-engineering-patterns/references/system-prompts.md +189 -0
- package/skills/prompt-engineering-patterns/scripts/optimize-prompt.py +279 -0
- package/skills/protocol-reverse-engineering/SKILL.md +29 -0
- package/skills/protocol-reverse-engineering/resources/implementation-playbook.md +509 -0
- package/skills/python-development-python-scaffold/SKILL.md +331 -0
- package/skills/python-packaging/SKILL.md +36 -0
- package/skills/python-packaging/resources/implementation-playbook.md +869 -0
- package/skills/python-performance-optimization/SKILL.md +36 -0
- package/skills/python-performance-optimization/resources/implementation-playbook.md +868 -0
- package/skills/python-pro/SKILL.md +158 -0
- package/skills/python-testing-patterns/SKILL.md +37 -0
- package/skills/python-testing-patterns/resources/implementation-playbook.md +906 -0
- package/skills/quant-analyst/SKILL.md +53 -0
- package/skills/rag-implementation/SKILL.md +421 -0
- package/skills/react-modernization/SKILL.md +34 -0
- package/skills/react-modernization/resources/implementation-playbook.md +512 -0
- package/skills/react-native-architecture/SKILL.md +33 -0
- package/skills/react-native-architecture/resources/implementation-playbook.md +670 -0
- package/skills/react-state-management/SKILL.md +441 -0
- package/skills/reference-builder/SKILL.md +188 -0
- package/skills/reverse-engineer/SKILL.md +173 -0
- package/skills/risk-manager/SKILL.md +61 -0
- package/skills/risk-metrics-calculation/SKILL.md +33 -0
- package/skills/risk-metrics-calculation/resources/implementation-playbook.md +554 -0
- package/skills/ruby-pro/SKILL.md +56 -0
- package/skills/rust-async-patterns/SKILL.md +33 -0
- package/skills/rust-async-patterns/resources/implementation-playbook.md +516 -0
- package/skills/rust-pro/SKILL.md +178 -0
- package/skills/saga-orchestration/SKILL.md +496 -0
- package/skills/sales-automator/SKILL.md +55 -0
- package/skills/sast-configuration/SKILL.md +212 -0
- package/skills/scala-pro/SKILL.md +82 -0
- package/skills/screen-reader-testing/SKILL.md +33 -0
- package/skills/screen-reader-testing/resources/implementation-playbook.md +544 -0
- package/skills/search-specialist/SKILL.md +80 -0
- package/skills/secrets-management/SKILL.md +364 -0
- package/skills/security-auditor/SKILL.md +169 -0
- package/skills/security-compliance-compliance-check/SKILL.md +55 -0
- package/skills/security-compliance-compliance-check/resources/implementation-playbook.md +963 -0
- package/skills/security-requirement-extraction/SKILL.md +33 -0
- package/skills/security-requirement-extraction/resources/implementation-playbook.md +676 -0
- package/skills/security-scanning-security-dependencies/SKILL.md +43 -0
- package/skills/security-scanning-security-dependencies/resources/implementation-playbook.md +544 -0
- package/skills/security-scanning-security-hardening/SKILL.md +147 -0
- package/skills/security-scanning-security-sast/SKILL.md +495 -0
- package/skills/seo-authority-builder/SKILL.md +136 -0
- package/skills/seo-cannibalization-detector/SKILL.md +123 -0
- package/skills/seo-content-auditor/SKILL.md +83 -0
- package/skills/seo-content-planner/SKILL.md +108 -0
- package/skills/seo-content-refresher/SKILL.md +118 -0
- package/skills/seo-content-writer/SKILL.md +96 -0
- package/skills/seo-keyword-strategist/SKILL.md +95 -0
- package/skills/seo-meta-optimizer/SKILL.md +92 -0
- package/skills/seo-snippet-hunter/SKILL.md +114 -0
- package/skills/seo-structure-architect/SKILL.md +108 -0
- package/skills/service-mesh-expert/SKILL.md +58 -0
- package/skills/service-mesh-observability/SKILL.md +395 -0
- package/skills/shellcheck-configuration/SKILL.md +466 -0
- package/skills/similarity-search-patterns/SKILL.md +33 -0
- package/skills/similarity-search-patterns/resources/implementation-playbook.md +557 -0
- package/skills/slo-implementation/SKILL.md +341 -0
- package/skills/solidity-security/SKILL.md +34 -0
- package/skills/solidity-security/resources/implementation-playbook.md +524 -0
- package/skills/spark-optimization/SKILL.md +427 -0
- package/skills/sql-optimization-patterns/SKILL.md +35 -0
- package/skills/sql-optimization-patterns/resources/implementation-playbook.md +504 -0
- package/skills/sql-pro/SKILL.md +173 -0
- package/skills/startup-analyst/SKILL.md +328 -0
- package/skills/startup-business-analyst-business-case/SKILL.md +487 -0
- package/skills/startup-business-analyst-financial-projections/SKILL.md +353 -0
- package/skills/startup-business-analyst-market-opportunity/SKILL.md +240 -0
- package/skills/startup-financial-modeling/SKILL.md +467 -0
- package/skills/startup-metrics-framework/SKILL.md +34 -0
- package/skills/startup-metrics-framework/resources/implementation-playbook.md +500 -0
- package/skills/stride-analysis-patterns/SKILL.md +33 -0
- package/skills/stride-analysis-patterns/resources/implementation-playbook.md +655 -0
- package/skills/stripe-integration/SKILL.md +454 -0
- package/skills/systems-programming-rust-project/SKILL.md +440 -0
- package/skills/tailwind-design-system/SKILL.md +33 -0
- package/skills/tailwind-design-system/resources/implementation-playbook.md +665 -0
- package/skills/tdd-orchestrator/SKILL.md +205 -0
- package/skills/tdd-workflows-tdd-cycle/SKILL.md +221 -0
- package/skills/tdd-workflows-tdd-green/SKILL.md +73 -0
- package/skills/tdd-workflows-tdd-green/resources/implementation-playbook.md +870 -0
- package/skills/tdd-workflows-tdd-red/SKILL.md +164 -0
- package/skills/tdd-workflows-tdd-refactor/SKILL.md +187 -0
- package/skills/team-collaboration-issue/SKILL.md +37 -0
- package/skills/team-collaboration-issue/resources/implementation-playbook.md +640 -0
- package/skills/team-collaboration-standup-notes/SKILL.md +44 -0
- package/skills/team-collaboration-standup-notes/resources/implementation-playbook.md +768 -0
- package/skills/team-composition-analysis/SKILL.md +413 -0
- package/skills/temporal-python-pro/SKILL.md +370 -0
- package/skills/temporal-python-testing/SKILL.md +170 -0
- package/skills/temporal-python-testing/resources/integration-testing.md +455 -0
- package/skills/temporal-python-testing/resources/local-setup.md +553 -0
- package/skills/temporal-python-testing/resources/replay-testing.md +462 -0
- package/skills/temporal-python-testing/resources/unit-testing.md +328 -0
- package/skills/terraform-module-library/SKILL.md +261 -0
- package/skills/terraform-module-library/references/aws-modules.md +63 -0
- package/skills/terraform-specialist/SKILL.md +166 -0
- package/skills/test-automator/SKILL.md +224 -0
- package/skills/threat-mitigation-mapping/SKILL.md +33 -0
- package/skills/threat-mitigation-mapping/resources/implementation-playbook.md +744 -0
- package/skills/threat-modeling-expert/SKILL.md +60 -0
- package/skills/track-management/SKILL.md +38 -0
- package/skills/track-management/resources/implementation-playbook.md +591 -0
- package/skills/turborepo-caching/SKILL.md +419 -0
- package/skills/tutorial-engineer/SKILL.md +139 -0
- package/skills/typescript-advanced-types/SKILL.md +35 -0
- package/skills/typescript-advanced-types/resources/implementation-playbook.md +716 -0
- package/skills/typescript-pro/SKILL.md +55 -0
- package/skills/ui-minimal/SKILL.md +23 -0
- package/skills/ui-ux-designer/SKILL.md +209 -0
- package/skills/ui-visual-validator/SKILL.md +214 -0
- package/skills/unit-testing-test-generate/SKILL.md +319 -0
- package/skills/unity-developer/SKILL.md +230 -0
- package/skills/unity-ecs-patterns/SKILL.md +33 -0
- package/skills/unity-ecs-patterns/resources/implementation-playbook.md +625 -0
- package/skills/uv-package-manager/SKILL.md +37 -0
- package/skills/uv-package-manager/resources/implementation-playbook.md +830 -0
- package/skills/vector-database-engineer/SKILL.md +60 -0
- package/skills/vector-index-tuning/SKILL.md +42 -0
- package/skills/vector-index-tuning/resources/implementation-playbook.md +507 -0
- package/skills/wcag-audit-patterns/SKILL.md +41 -0
- package/skills/wcag-audit-patterns/resources/implementation-playbook.md +541 -0
- package/skills/web3-testing/SKILL.md +427 -0
- package/skills/workflow-orchestration-patterns/SKILL.md +333 -0
- package/skills/workflow-patterns/SKILL.md +38 -0
- package/skills/workflow-patterns/resources/implementation-playbook.md +621 -0
|
@@ -0,0 +1,1441 @@
|
|
|
1
|
+
# Cloud Cost Optimization Implementation Playbook
|
|
2
|
+
|
|
3
|
+
This file contains detailed patterns, checklists, and code samples referenced by the skill.
|
|
4
|
+
|
|
5
|
+
## Instructions
|
|
6
|
+
|
|
7
|
+
### 1. Cost Analysis and Visibility
|
|
8
|
+
|
|
9
|
+
Implement comprehensive cost analysis:
|
|
10
|
+
|
|
11
|
+
**Cost Analysis Framework**
|
|
12
|
+
```python
|
|
13
|
+
import boto3
|
|
14
|
+
import pandas as pd
|
|
15
|
+
from datetime import datetime, timedelta
|
|
16
|
+
from typing import Dict, List, Any
|
|
17
|
+
import json
|
|
18
|
+
|
|
19
|
+
class CloudCostAnalyzer:
|
|
20
|
+
def __init__(self, cloud_provider: str):
|
|
21
|
+
self.provider = cloud_provider
|
|
22
|
+
self.client = self._initialize_client()
|
|
23
|
+
self.cost_data = None
|
|
24
|
+
|
|
25
|
+
def analyze_costs(self, time_period: int = 30):
|
|
26
|
+
"""Comprehensive cost analysis"""
|
|
27
|
+
analysis = {
|
|
28
|
+
'total_cost': self._get_total_cost(time_period),
|
|
29
|
+
'cost_by_service': self._analyze_by_service(time_period),
|
|
30
|
+
'cost_by_resource': self._analyze_by_resource(time_period),
|
|
31
|
+
'cost_trends': self._analyze_trends(time_period),
|
|
32
|
+
'anomalies': self._detect_anomalies(time_period),
|
|
33
|
+
'waste_analysis': self._identify_waste(),
|
|
34
|
+
'optimization_opportunities': self._find_opportunities()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return self._generate_report(analysis)
|
|
38
|
+
|
|
39
|
+
def _analyze_by_service(self, days: int):
|
|
40
|
+
"""Analyze costs by service"""
|
|
41
|
+
if self.provider == 'aws':
|
|
42
|
+
ce = boto3.client('ce')
|
|
43
|
+
|
|
44
|
+
response = ce.get_cost_and_usage(
|
|
45
|
+
TimePeriod={
|
|
46
|
+
'Start': (datetime.now() - timedelta(days=days)).strftime('%Y-%m-%d'),
|
|
47
|
+
'End': datetime.now().strftime('%Y-%m-%d')
|
|
48
|
+
},
|
|
49
|
+
Granularity='DAILY',
|
|
50
|
+
Metrics=['UnblendedCost'],
|
|
51
|
+
GroupBy=[
|
|
52
|
+
{'Type': 'DIMENSION', 'Key': 'SERVICE'}
|
|
53
|
+
]
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# Process response
|
|
57
|
+
service_costs = {}
|
|
58
|
+
for result in response['ResultsByTime']:
|
|
59
|
+
for group in result['Groups']:
|
|
60
|
+
service = group['Keys'][0]
|
|
61
|
+
cost = float(group['Metrics']['UnblendedCost']['Amount'])
|
|
62
|
+
|
|
63
|
+
if service not in service_costs:
|
|
64
|
+
service_costs[service] = []
|
|
65
|
+
service_costs[service].append(cost)
|
|
66
|
+
|
|
67
|
+
# Calculate totals and trends
|
|
68
|
+
analysis = {}
|
|
69
|
+
for service, costs in service_costs.items():
|
|
70
|
+
analysis[service] = {
|
|
71
|
+
'total': sum(costs),
|
|
72
|
+
'average_daily': sum(costs) / len(costs),
|
|
73
|
+
'trend': self._calculate_trend(costs),
|
|
74
|
+
'percentage': (sum(costs) / self._get_total_cost(days)) * 100
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return analysis
|
|
78
|
+
|
|
79
|
+
def _identify_waste(self):
|
|
80
|
+
"""Identify wasted resources"""
|
|
81
|
+
waste_analysis = {
|
|
82
|
+
'unused_resources': self._find_unused_resources(),
|
|
83
|
+
'oversized_resources': self._find_oversized_resources(),
|
|
84
|
+
'unattached_storage': self._find_unattached_storage(),
|
|
85
|
+
'idle_load_balancers': self._find_idle_load_balancers(),
|
|
86
|
+
'old_snapshots': self._find_old_snapshots(),
|
|
87
|
+
'untagged_resources': self._find_untagged_resources()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
total_waste = sum(item['estimated_savings']
|
|
91
|
+
for category in waste_analysis.values()
|
|
92
|
+
for item in category)
|
|
93
|
+
|
|
94
|
+
waste_analysis['total_potential_savings'] = total_waste
|
|
95
|
+
|
|
96
|
+
return waste_analysis
|
|
97
|
+
|
|
98
|
+
def _find_unused_resources(self):
|
|
99
|
+
"""Find resources with no usage"""
|
|
100
|
+
unused = []
|
|
101
|
+
|
|
102
|
+
if self.provider == 'aws':
|
|
103
|
+
# Check EC2 instances
|
|
104
|
+
ec2 = boto3.client('ec2')
|
|
105
|
+
cloudwatch = boto3.client('cloudwatch')
|
|
106
|
+
|
|
107
|
+
instances = ec2.describe_instances(
|
|
108
|
+
Filters=[{'Name': 'instance-state-name', 'Values': ['running']}]
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
for reservation in instances['Reservations']:
|
|
112
|
+
for instance in reservation['Instances']:
|
|
113
|
+
# Check CPU utilization
|
|
114
|
+
metrics = cloudwatch.get_metric_statistics(
|
|
115
|
+
Namespace='AWS/EC2',
|
|
116
|
+
MetricName='CPUUtilization',
|
|
117
|
+
Dimensions=[
|
|
118
|
+
{'Name': 'InstanceId', 'Value': instance['InstanceId']}
|
|
119
|
+
],
|
|
120
|
+
StartTime=datetime.now() - timedelta(days=7),
|
|
121
|
+
EndTime=datetime.now(),
|
|
122
|
+
Period=3600,
|
|
123
|
+
Statistics=['Average']
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
if metrics['Datapoints']:
|
|
127
|
+
avg_cpu = sum(d['Average'] for d in metrics['Datapoints']) / len(metrics['Datapoints'])
|
|
128
|
+
|
|
129
|
+
if avg_cpu < 5: # Less than 5% CPU usage
|
|
130
|
+
unused.append({
|
|
131
|
+
'resource_type': 'EC2 Instance',
|
|
132
|
+
'resource_id': instance['InstanceId'],
|
|
133
|
+
'reason': f'Average CPU: {avg_cpu:.2f}%',
|
|
134
|
+
'estimated_savings': self._calculate_instance_cost(instance)
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
return unused
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 2. Resource Rightsizing
|
|
141
|
+
|
|
142
|
+
Implement intelligent rightsizing:
|
|
143
|
+
|
|
144
|
+
**Rightsizing Engine**
|
|
145
|
+
```python
|
|
146
|
+
class ResourceRightsizer:
|
|
147
|
+
def __init__(self):
|
|
148
|
+
self.utilization_thresholds = {
|
|
149
|
+
'cpu_low': 20,
|
|
150
|
+
'cpu_high': 80,
|
|
151
|
+
'memory_low': 30,
|
|
152
|
+
'memory_high': 85,
|
|
153
|
+
'network_low': 10,
|
|
154
|
+
'network_high': 70
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
def analyze_rightsizing_opportunities(self):
|
|
158
|
+
"""Find rightsizing opportunities"""
|
|
159
|
+
opportunities = {
|
|
160
|
+
'ec2_instances': self._rightsize_ec2(),
|
|
161
|
+
'rds_instances': self._rightsize_rds(),
|
|
162
|
+
'containers': self._rightsize_containers(),
|
|
163
|
+
'lambda_functions': self._rightsize_lambda(),
|
|
164
|
+
'storage_volumes': self._rightsize_storage()
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return self._prioritize_opportunities(opportunities)
|
|
168
|
+
|
|
169
|
+
def _rightsize_ec2(self):
|
|
170
|
+
"""Rightsize EC2 instances"""
|
|
171
|
+
recommendations = []
|
|
172
|
+
|
|
173
|
+
instances = self._get_running_instances()
|
|
174
|
+
|
|
175
|
+
for instance in instances:
|
|
176
|
+
# Get utilization metrics
|
|
177
|
+
utilization = self._get_instance_utilization(instance['InstanceId'])
|
|
178
|
+
|
|
179
|
+
# Determine if oversized or undersized
|
|
180
|
+
current_type = instance['InstanceType']
|
|
181
|
+
recommended_type = self._recommend_instance_type(
|
|
182
|
+
current_type,
|
|
183
|
+
utilization
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
if recommended_type != current_type:
|
|
187
|
+
current_cost = self._get_instance_cost(current_type)
|
|
188
|
+
new_cost = self._get_instance_cost(recommended_type)
|
|
189
|
+
|
|
190
|
+
recommendations.append({
|
|
191
|
+
'resource_id': instance['InstanceId'],
|
|
192
|
+
'current_type': current_type,
|
|
193
|
+
'recommended_type': recommended_type,
|
|
194
|
+
'reason': self._generate_reason(utilization),
|
|
195
|
+
'current_cost': current_cost,
|
|
196
|
+
'new_cost': new_cost,
|
|
197
|
+
'monthly_savings': (current_cost - new_cost) * 730,
|
|
198
|
+
'effort': 'medium',
|
|
199
|
+
'risk': 'low' if 'downsize' in self._generate_reason(utilization) else 'medium'
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
return recommendations
|
|
203
|
+
|
|
204
|
+
def _recommend_instance_type(self, current_type: str, utilization: Dict):
|
|
205
|
+
"""Recommend optimal instance type"""
|
|
206
|
+
# Parse current instance family and size
|
|
207
|
+
family, size = self._parse_instance_type(current_type)
|
|
208
|
+
|
|
209
|
+
# Calculate required resources
|
|
210
|
+
required_cpu = self._calculate_required_cpu(utilization['cpu'])
|
|
211
|
+
required_memory = self._calculate_required_memory(utilization['memory'])
|
|
212
|
+
|
|
213
|
+
# Find best matching instance
|
|
214
|
+
instance_catalog = self._get_instance_catalog()
|
|
215
|
+
|
|
216
|
+
candidates = []
|
|
217
|
+
for instance_type, specs in instance_catalog.items():
|
|
218
|
+
if (specs['vcpu'] >= required_cpu and
|
|
219
|
+
specs['memory'] >= required_memory):
|
|
220
|
+
candidates.append({
|
|
221
|
+
'type': instance_type,
|
|
222
|
+
'cost': specs['cost'],
|
|
223
|
+
'vcpu': specs['vcpu'],
|
|
224
|
+
'memory': specs['memory'],
|
|
225
|
+
'efficiency_score': self._calculate_efficiency_score(
|
|
226
|
+
specs, required_cpu, required_memory
|
|
227
|
+
)
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
# Select best candidate
|
|
231
|
+
if candidates:
|
|
232
|
+
best = sorted(candidates,
|
|
233
|
+
key=lambda x: (x['efficiency_score'], x['cost']))[0]
|
|
234
|
+
return best['type']
|
|
235
|
+
|
|
236
|
+
return current_type
|
|
237
|
+
|
|
238
|
+
def create_rightsizing_automation(self):
|
|
239
|
+
"""Automated rightsizing implementation"""
|
|
240
|
+
return '''
|
|
241
|
+
import boto3
|
|
242
|
+
from datetime import datetime
|
|
243
|
+
import logging
|
|
244
|
+
|
|
245
|
+
class AutomatedRightsizer:
|
|
246
|
+
def __init__(self):
|
|
247
|
+
self.ec2 = boto3.client('ec2')
|
|
248
|
+
self.cloudwatch = boto3.client('cloudwatch')
|
|
249
|
+
self.logger = logging.getLogger(__name__)
|
|
250
|
+
|
|
251
|
+
def execute_rightsizing(self, recommendations: List[Dict], dry_run: bool = True):
|
|
252
|
+
"""Execute rightsizing recommendations"""
|
|
253
|
+
results = []
|
|
254
|
+
|
|
255
|
+
for recommendation in recommendations:
|
|
256
|
+
try:
|
|
257
|
+
if recommendation['risk'] == 'low' or self._get_approval(recommendation):
|
|
258
|
+
result = self._resize_instance(
|
|
259
|
+
recommendation['resource_id'],
|
|
260
|
+
recommendation['recommended_type'],
|
|
261
|
+
dry_run=dry_run
|
|
262
|
+
)
|
|
263
|
+
results.append(result)
|
|
264
|
+
except Exception as e:
|
|
265
|
+
self.logger.error(f"Failed to resize {recommendation['resource_id']}: {e}")
|
|
266
|
+
|
|
267
|
+
return results
|
|
268
|
+
|
|
269
|
+
def _resize_instance(self, instance_id: str, new_type: str, dry_run: bool):
|
|
270
|
+
"""Resize an EC2 instance"""
|
|
271
|
+
# Create snapshot for rollback
|
|
272
|
+
snapshot_id = self._create_snapshot(instance_id)
|
|
273
|
+
|
|
274
|
+
try:
|
|
275
|
+
# Stop instance
|
|
276
|
+
if not dry_run:
|
|
277
|
+
self.ec2.stop_instances(InstanceIds=[instance_id])
|
|
278
|
+
self._wait_for_state(instance_id, 'stopped')
|
|
279
|
+
|
|
280
|
+
# Change instance type
|
|
281
|
+
self.ec2.modify_instance_attribute(
|
|
282
|
+
InstanceId=instance_id,
|
|
283
|
+
InstanceType={'Value': new_type},
|
|
284
|
+
DryRun=dry_run
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
# Start instance
|
|
288
|
+
if not dry_run:
|
|
289
|
+
self.ec2.start_instances(InstanceIds=[instance_id])
|
|
290
|
+
self._wait_for_state(instance_id, 'running')
|
|
291
|
+
|
|
292
|
+
return {
|
|
293
|
+
'instance_id': instance_id,
|
|
294
|
+
'status': 'success',
|
|
295
|
+
'new_type': new_type,
|
|
296
|
+
'snapshot_id': snapshot_id
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
except Exception as e:
|
|
300
|
+
# Rollback on failure
|
|
301
|
+
if not dry_run:
|
|
302
|
+
self._rollback_instance(instance_id, snapshot_id)
|
|
303
|
+
raise
|
|
304
|
+
'''
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### 3. Reserved Instances and Savings Plans
|
|
308
|
+
|
|
309
|
+
Optimize commitment-based discounts:
|
|
310
|
+
|
|
311
|
+
**Reservation Optimizer**
|
|
312
|
+
```python
|
|
313
|
+
class ReservationOptimizer:
|
|
314
|
+
def __init__(self):
|
|
315
|
+
self.usage_history = None
|
|
316
|
+
self.existing_reservations = None
|
|
317
|
+
|
|
318
|
+
def analyze_reservation_opportunities(self):
|
|
319
|
+
"""Analyze opportunities for reservations"""
|
|
320
|
+
analysis = {
|
|
321
|
+
'current_coverage': self._analyze_current_coverage(),
|
|
322
|
+
'usage_patterns': self._analyze_usage_patterns(),
|
|
323
|
+
'recommendations': self._generate_recommendations(),
|
|
324
|
+
'roi_analysis': self._calculate_roi(),
|
|
325
|
+
'risk_assessment': self._assess_commitment_risk()
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return analysis
|
|
329
|
+
|
|
330
|
+
def _analyze_usage_patterns(self):
|
|
331
|
+
"""Analyze historical usage patterns"""
|
|
332
|
+
# Get 12 months of usage data
|
|
333
|
+
usage_data = self._get_historical_usage(months=12)
|
|
334
|
+
|
|
335
|
+
patterns = {
|
|
336
|
+
'stable_workloads': [],
|
|
337
|
+
'variable_workloads': [],
|
|
338
|
+
'seasonal_patterns': [],
|
|
339
|
+
'growth_trends': []
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
# Analyze each instance family
|
|
343
|
+
for family in self._get_instance_families(usage_data):
|
|
344
|
+
family_usage = self._filter_by_family(usage_data, family)
|
|
345
|
+
|
|
346
|
+
# Calculate stability metrics
|
|
347
|
+
stability = self._calculate_stability(family_usage)
|
|
348
|
+
|
|
349
|
+
if stability['coefficient_of_variation'] < 0.1:
|
|
350
|
+
patterns['stable_workloads'].append({
|
|
351
|
+
'family': family,
|
|
352
|
+
'average_usage': stability['mean'],
|
|
353
|
+
'min_usage': stability['min'],
|
|
354
|
+
'recommendation': 'reserved_instance',
|
|
355
|
+
'term': '3_year',
|
|
356
|
+
'payment': 'all_upfront'
|
|
357
|
+
})
|
|
358
|
+
elif stability['coefficient_of_variation'] < 0.3:
|
|
359
|
+
patterns['variable_workloads'].append({
|
|
360
|
+
'family': family,
|
|
361
|
+
'average_usage': stability['mean'],
|
|
362
|
+
'baseline': stability['percentile_25'],
|
|
363
|
+
'recommendation': 'savings_plan',
|
|
364
|
+
'commitment': stability['percentile_25']
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
# Check for seasonal patterns
|
|
368
|
+
if self._has_seasonal_pattern(family_usage):
|
|
369
|
+
patterns['seasonal_patterns'].append({
|
|
370
|
+
'family': family,
|
|
371
|
+
'pattern': self._identify_seasonal_pattern(family_usage),
|
|
372
|
+
'recommendation': 'spot_with_savings_plan_baseline'
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
return patterns
|
|
376
|
+
|
|
377
|
+
def _generate_recommendations(self):
|
|
378
|
+
"""Generate reservation recommendations"""
|
|
379
|
+
recommendations = []
|
|
380
|
+
|
|
381
|
+
patterns = self._analyze_usage_patterns()
|
|
382
|
+
current_costs = self._calculate_current_costs()
|
|
383
|
+
|
|
384
|
+
# Reserved Instance recommendations
|
|
385
|
+
for workload in patterns['stable_workloads']:
|
|
386
|
+
ri_options = self._calculate_ri_options(workload)
|
|
387
|
+
|
|
388
|
+
for option in ri_options:
|
|
389
|
+
savings = current_costs[workload['family']] - option['total_cost']
|
|
390
|
+
|
|
391
|
+
if savings > 0:
|
|
392
|
+
recommendations.append({
|
|
393
|
+
'type': 'reserved_instance',
|
|
394
|
+
'family': workload['family'],
|
|
395
|
+
'quantity': option['quantity'],
|
|
396
|
+
'term': option['term'],
|
|
397
|
+
'payment': option['payment_option'],
|
|
398
|
+
'upfront_cost': option['upfront_cost'],
|
|
399
|
+
'monthly_cost': option['monthly_cost'],
|
|
400
|
+
'total_savings': savings,
|
|
401
|
+
'break_even_months': option['upfront_cost'] / (savings / 36),
|
|
402
|
+
'confidence': 'high'
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
# Savings Plan recommendations
|
|
406
|
+
for workload in patterns['variable_workloads']:
|
|
407
|
+
sp_options = self._calculate_savings_plan_options(workload)
|
|
408
|
+
|
|
409
|
+
for option in sp_options:
|
|
410
|
+
recommendations.append({
|
|
411
|
+
'type': 'savings_plan',
|
|
412
|
+
'commitment_type': option['type'],
|
|
413
|
+
'hourly_commitment': option['commitment'],
|
|
414
|
+
'term': option['term'],
|
|
415
|
+
'estimated_savings': option['savings'],
|
|
416
|
+
'flexibility': option['flexibility_score'],
|
|
417
|
+
'confidence': 'medium'
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
return sorted(recommendations, key=lambda x: x.get('total_savings', 0), reverse=True)
|
|
421
|
+
|
|
422
|
+
def create_reservation_dashboard(self):
|
|
423
|
+
"""Create reservation tracking dashboard"""
|
|
424
|
+
return '''
|
|
425
|
+
<!DOCTYPE html>
|
|
426
|
+
<html>
|
|
427
|
+
<head>
|
|
428
|
+
<title>Reservation & Savings Dashboard</title>
|
|
429
|
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
430
|
+
</head>
|
|
431
|
+
<body>
|
|
432
|
+
<div class="dashboard">
|
|
433
|
+
<div class="summary-cards">
|
|
434
|
+
<div class="card">
|
|
435
|
+
<h3>Current Coverage</h3>
|
|
436
|
+
<div class="metric">{coverage_percentage}%</div>
|
|
437
|
+
<div class="sub-metric">On-Demand: ${on_demand_cost}</div>
|
|
438
|
+
<div class="sub-metric">Reserved: ${reserved_cost}</div>
|
|
439
|
+
</div>
|
|
440
|
+
|
|
441
|
+
<div class="card">
|
|
442
|
+
<h3>Potential Savings</h3>
|
|
443
|
+
<div class="metric">${potential_savings}/month</div>
|
|
444
|
+
<div class="sub-metric">{recommendations_count} opportunities</div>
|
|
445
|
+
</div>
|
|
446
|
+
|
|
447
|
+
<div class="card">
|
|
448
|
+
<h3>Expiring Soon</h3>
|
|
449
|
+
<div class="metric">{expiring_count} RIs</div>
|
|
450
|
+
<div class="sub-metric">Next 30 days</div>
|
|
451
|
+
</div>
|
|
452
|
+
</div>
|
|
453
|
+
|
|
454
|
+
<div class="charts">
|
|
455
|
+
<canvas id="coverageChart"></canvas>
|
|
456
|
+
<canvas id="savingsChart"></canvas>
|
|
457
|
+
</div>
|
|
458
|
+
|
|
459
|
+
<div class="recommendations-table">
|
|
460
|
+
<h3>Top Recommendations</h3>
|
|
461
|
+
<table>
|
|
462
|
+
<tr>
|
|
463
|
+
<th>Type</th>
|
|
464
|
+
<th>Resource</th>
|
|
465
|
+
<th>Term</th>
|
|
466
|
+
<th>Upfront</th>
|
|
467
|
+
<th>Monthly Savings</th>
|
|
468
|
+
<th>ROI</th>
|
|
469
|
+
<th>Action</th>
|
|
470
|
+
</tr>
|
|
471
|
+
{recommendation_rows}
|
|
472
|
+
</table>
|
|
473
|
+
</div>
|
|
474
|
+
</div>
|
|
475
|
+
</body>
|
|
476
|
+
</html>
|
|
477
|
+
'''
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
### 4. Spot Instance Optimization
|
|
481
|
+
|
|
482
|
+
Leverage spot instances effectively:
|
|
483
|
+
|
|
484
|
+
**Spot Instance Manager**
|
|
485
|
+
```python
|
|
486
|
+
class SpotInstanceOptimizer:
|
|
487
|
+
def __init__(self):
|
|
488
|
+
self.spot_advisor = self._init_spot_advisor()
|
|
489
|
+
self.interruption_handler = None
|
|
490
|
+
|
|
491
|
+
def identify_spot_opportunities(self):
|
|
492
|
+
"""Identify workloads suitable for spot"""
|
|
493
|
+
workloads = self._analyze_workloads()
|
|
494
|
+
|
|
495
|
+
spot_candidates = {
|
|
496
|
+
'batch_processing': [],
|
|
497
|
+
'dev_test': [],
|
|
498
|
+
'stateless_apps': [],
|
|
499
|
+
'ci_cd': [],
|
|
500
|
+
'data_processing': []
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
for workload in workloads:
|
|
504
|
+
suitability = self._assess_spot_suitability(workload)
|
|
505
|
+
|
|
506
|
+
if suitability['score'] > 0.7:
|
|
507
|
+
spot_candidates[workload['type']].append({
|
|
508
|
+
'workload': workload['name'],
|
|
509
|
+
'current_cost': workload['cost'],
|
|
510
|
+
'spot_savings': workload['cost'] * 0.7, # ~70% savings
|
|
511
|
+
'interruption_tolerance': suitability['interruption_tolerance'],
|
|
512
|
+
'recommended_strategy': self._recommend_spot_strategy(workload)
|
|
513
|
+
})
|
|
514
|
+
|
|
515
|
+
return spot_candidates
|
|
516
|
+
|
|
517
|
+
def _recommend_spot_strategy(self, workload):
|
|
518
|
+
"""Recommend spot instance strategy"""
|
|
519
|
+
if workload['interruption_tolerance'] == 'high':
|
|
520
|
+
return {
|
|
521
|
+
'strategy': 'spot_fleet_diverse',
|
|
522
|
+
'instance_pools': 10,
|
|
523
|
+
'allocation_strategy': 'capacity-optimized',
|
|
524
|
+
'on_demand_base': 0,
|
|
525
|
+
'spot_percentage': 100
|
|
526
|
+
}
|
|
527
|
+
elif workload['interruption_tolerance'] == 'medium':
|
|
528
|
+
return {
|
|
529
|
+
'strategy': 'mixed_instances',
|
|
530
|
+
'on_demand_base': 25,
|
|
531
|
+
'spot_percentage': 75,
|
|
532
|
+
'spot_allocation': 'lowest-price'
|
|
533
|
+
}
|
|
534
|
+
else:
|
|
535
|
+
return {
|
|
536
|
+
'strategy': 'spot_with_fallback',
|
|
537
|
+
'primary': 'spot',
|
|
538
|
+
'fallback': 'on-demand',
|
|
539
|
+
'checkpointing': True
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
def create_spot_configuration(self):
|
|
543
|
+
"""Create spot instance configuration"""
|
|
544
|
+
return '''
|
|
545
|
+
# Terraform configuration for Spot instances
|
|
546
|
+
resource "aws_spot_fleet_request" "processing_fleet" {
|
|
547
|
+
iam_fleet_role = aws_iam_role.spot_fleet.arn
|
|
548
|
+
|
|
549
|
+
allocation_strategy = "diversified"
|
|
550
|
+
target_capacity = 100
|
|
551
|
+
valid_until = timeadd(timestamp(), "168h")
|
|
552
|
+
|
|
553
|
+
# Define multiple launch specifications for diversity
|
|
554
|
+
dynamic "launch_specification" {
|
|
555
|
+
for_each = var.spot_instance_types
|
|
556
|
+
|
|
557
|
+
content {
|
|
558
|
+
instance_type = launch_specification.value
|
|
559
|
+
ami = var.ami_id
|
|
560
|
+
key_name = var.key_name
|
|
561
|
+
subnet_id = var.subnet_ids[launch_specification.key % length(var.subnet_ids)]
|
|
562
|
+
|
|
563
|
+
weighted_capacity = var.instance_weights[launch_specification.value]
|
|
564
|
+
spot_price = var.max_spot_prices[launch_specification.value]
|
|
565
|
+
|
|
566
|
+
user_data = base64encode(templatefile("${path.module}/spot-init.sh", {
|
|
567
|
+
interruption_handler = true
|
|
568
|
+
checkpoint_s3_bucket = var.checkpoint_bucket
|
|
569
|
+
}))
|
|
570
|
+
|
|
571
|
+
tags = {
|
|
572
|
+
Name = "spot-processing-${launch_specification.key}"
|
|
573
|
+
Type = "spot"
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
# Interruption handling
|
|
579
|
+
lifecycle {
|
|
580
|
+
create_before_destroy = true
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
# Spot interruption handler
|
|
585
|
+
resource "aws_lambda_function" "spot_interruption_handler" {
|
|
586
|
+
filename = "spot-handler.zip"
|
|
587
|
+
function_name = "spot-interruption-handler"
|
|
588
|
+
role = aws_iam_role.lambda_role.arn
|
|
589
|
+
handler = "handler.main"
|
|
590
|
+
runtime = "python3.9"
|
|
591
|
+
|
|
592
|
+
environment {
|
|
593
|
+
variables = {
|
|
594
|
+
CHECKPOINT_BUCKET = var.checkpoint_bucket
|
|
595
|
+
SNS_TOPIC_ARN = aws_sns_topic.spot_interruptions.arn
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
'''
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
### 5. Storage Optimization
|
|
603
|
+
|
|
604
|
+
Optimize storage costs:
|
|
605
|
+
|
|
606
|
+
**Storage Optimizer**
|
|
607
|
+
```python
|
|
608
|
+
class StorageOptimizer:
|
|
609
|
+
def analyze_storage_costs(self):
|
|
610
|
+
"""Comprehensive storage analysis"""
|
|
611
|
+
analysis = {
|
|
612
|
+
'ebs_volumes': self._analyze_ebs_volumes(),
|
|
613
|
+
's3_buckets': self._analyze_s3_buckets(),
|
|
614
|
+
'snapshots': self._analyze_snapshots(),
|
|
615
|
+
'lifecycle_opportunities': self._find_lifecycle_opportunities(),
|
|
616
|
+
'compression_opportunities': self._find_compression_opportunities()
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
return analysis
|
|
620
|
+
|
|
621
|
+
def _analyze_s3_buckets(self):
|
|
622
|
+
"""Analyze S3 bucket costs and optimization"""
|
|
623
|
+
s3 = boto3.client('s3')
|
|
624
|
+
cloudwatch = boto3.client('cloudwatch')
|
|
625
|
+
|
|
626
|
+
buckets = s3.list_buckets()['Buckets']
|
|
627
|
+
bucket_analysis = []
|
|
628
|
+
|
|
629
|
+
for bucket in buckets:
|
|
630
|
+
bucket_name = bucket['Name']
|
|
631
|
+
|
|
632
|
+
# Get storage metrics
|
|
633
|
+
metrics = self._get_s3_metrics(bucket_name)
|
|
634
|
+
|
|
635
|
+
# Analyze storage classes
|
|
636
|
+
storage_class_distribution = self._get_storage_class_distribution(bucket_name)
|
|
637
|
+
|
|
638
|
+
# Calculate optimization potential
|
|
639
|
+
optimization = self._calculate_s3_optimization(
|
|
640
|
+
bucket_name,
|
|
641
|
+
metrics,
|
|
642
|
+
storage_class_distribution
|
|
643
|
+
)
|
|
644
|
+
|
|
645
|
+
bucket_analysis.append({
|
|
646
|
+
'bucket_name': bucket_name,
|
|
647
|
+
'total_size_gb': metrics['size_gb'],
|
|
648
|
+
'total_objects': metrics['object_count'],
|
|
649
|
+
'current_cost': metrics['monthly_cost'],
|
|
650
|
+
'storage_classes': storage_class_distribution,
|
|
651
|
+
'optimization_recommendations': optimization['recommendations'],
|
|
652
|
+
'potential_savings': optimization['savings']
|
|
653
|
+
})
|
|
654
|
+
|
|
655
|
+
return bucket_analysis
|
|
656
|
+
|
|
657
|
+
def create_lifecycle_policies(self):
|
|
658
|
+
"""Create S3 lifecycle policies"""
|
|
659
|
+
return '''
|
|
660
|
+
import boto3
|
|
661
|
+
from datetime import datetime
|
|
662
|
+
|
|
663
|
+
class S3LifecycleManager:
|
|
664
|
+
def __init__(self):
|
|
665
|
+
self.s3 = boto3.client('s3')
|
|
666
|
+
|
|
667
|
+
def create_intelligent_lifecycle(self, bucket_name: str, access_patterns: Dict):
|
|
668
|
+
"""Create lifecycle policy based on access patterns"""
|
|
669
|
+
|
|
670
|
+
rules = []
|
|
671
|
+
|
|
672
|
+
# Intelligent tiering for unknown access patterns
|
|
673
|
+
if access_patterns.get('unpredictable'):
|
|
674
|
+
rules.append({
|
|
675
|
+
'ID': 'intelligent-tiering',
|
|
676
|
+
'Status': 'Enabled',
|
|
677
|
+
'Transitions': [{
|
|
678
|
+
'Days': 1,
|
|
679
|
+
'StorageClass': 'INTELLIGENT_TIERING'
|
|
680
|
+
}]
|
|
681
|
+
})
|
|
682
|
+
|
|
683
|
+
# Standard lifecycle for predictable patterns
|
|
684
|
+
if access_patterns.get('predictable'):
|
|
685
|
+
rules.append({
|
|
686
|
+
'ID': 'standard-lifecycle',
|
|
687
|
+
'Status': 'Enabled',
|
|
688
|
+
'Transitions': [
|
|
689
|
+
{
|
|
690
|
+
'Days': 30,
|
|
691
|
+
'StorageClass': 'STANDARD_IA'
|
|
692
|
+
},
|
|
693
|
+
{
|
|
694
|
+
'Days': 90,
|
|
695
|
+
'StorageClass': 'GLACIER'
|
|
696
|
+
},
|
|
697
|
+
{
|
|
698
|
+
'Days': 180,
|
|
699
|
+
'StorageClass': 'DEEP_ARCHIVE'
|
|
700
|
+
}
|
|
701
|
+
]
|
|
702
|
+
})
|
|
703
|
+
|
|
704
|
+
# Delete old versions
|
|
705
|
+
rules.append({
|
|
706
|
+
'ID': 'delete-old-versions',
|
|
707
|
+
'Status': 'Enabled',
|
|
708
|
+
'NoncurrentVersionTransitions': [
|
|
709
|
+
{
|
|
710
|
+
'NoncurrentDays': 30,
|
|
711
|
+
'StorageClass': 'GLACIER'
|
|
712
|
+
}
|
|
713
|
+
],
|
|
714
|
+
'NoncurrentVersionExpiration': {
|
|
715
|
+
'NoncurrentDays': 90
|
|
716
|
+
}
|
|
717
|
+
})
|
|
718
|
+
|
|
719
|
+
# Apply lifecycle configuration
|
|
720
|
+
self.s3.put_bucket_lifecycle_configuration(
|
|
721
|
+
Bucket=bucket_name,
|
|
722
|
+
LifecycleConfiguration={'Rules': rules}
|
|
723
|
+
)
|
|
724
|
+
|
|
725
|
+
return rules
|
|
726
|
+
|
|
727
|
+
def optimize_ebs_volumes(self):
|
|
728
|
+
"""Optimize EBS volume types and sizes"""
|
|
729
|
+
ec2 = boto3.client('ec2')
|
|
730
|
+
|
|
731
|
+
volumes = ec2.describe_volumes()['Volumes']
|
|
732
|
+
optimizations = []
|
|
733
|
+
|
|
734
|
+
for volume in volumes:
|
|
735
|
+
# Analyze volume metrics
|
|
736
|
+
iops_usage = self._get_volume_iops_usage(volume['VolumeId'])
|
|
737
|
+
throughput_usage = self._get_volume_throughput_usage(volume['VolumeId'])
|
|
738
|
+
|
|
739
|
+
current_type = volume['VolumeType']
|
|
740
|
+
recommended_type = self._recommend_volume_type(
|
|
741
|
+
iops_usage,
|
|
742
|
+
throughput_usage,
|
|
743
|
+
volume['Size']
|
|
744
|
+
)
|
|
745
|
+
|
|
746
|
+
if recommended_type != current_type:
|
|
747
|
+
optimizations.append({
|
|
748
|
+
'volume_id': volume['VolumeId'],
|
|
749
|
+
'current_type': current_type,
|
|
750
|
+
'recommended_type': recommended_type,
|
|
751
|
+
'reason': self._get_optimization_reason(
|
|
752
|
+
current_type,
|
|
753
|
+
recommended_type,
|
|
754
|
+
iops_usage,
|
|
755
|
+
throughput_usage
|
|
756
|
+
),
|
|
757
|
+
'monthly_savings': self._calculate_volume_savings(
|
|
758
|
+
volume,
|
|
759
|
+
recommended_type
|
|
760
|
+
)
|
|
761
|
+
})
|
|
762
|
+
|
|
763
|
+
return optimizations
|
|
764
|
+
'''
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
### 6. Network Cost Optimization
|
|
768
|
+
|
|
769
|
+
Reduce network transfer costs:
|
|
770
|
+
|
|
771
|
+
**Network Cost Optimizer**
|
|
772
|
+
```python
|
|
773
|
+
class NetworkCostOptimizer:
|
|
774
|
+
def analyze_network_costs(self):
|
|
775
|
+
"""Analyze network transfer costs"""
|
|
776
|
+
analysis = {
|
|
777
|
+
'data_transfer_costs': self._analyze_data_transfer(),
|
|
778
|
+
'nat_gateway_costs': self._analyze_nat_gateways(),
|
|
779
|
+
'load_balancer_costs': self._analyze_load_balancers(),
|
|
780
|
+
'vpc_endpoint_opportunities': self._find_vpc_endpoint_opportunities(),
|
|
781
|
+
'cdn_optimization': self._analyze_cdn_usage()
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
return analysis
|
|
785
|
+
|
|
786
|
+
def _analyze_data_transfer(self):
|
|
787
|
+
"""Analyze data transfer patterns and costs"""
|
|
788
|
+
transfers = {
|
|
789
|
+
'inter_region': self._get_inter_region_transfers(),
|
|
790
|
+
'internet_egress': self._get_internet_egress(),
|
|
791
|
+
'inter_az': self._get_inter_az_transfers(),
|
|
792
|
+
'vpc_peering': self._get_vpc_peering_transfers()
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
recommendations = []
|
|
796
|
+
|
|
797
|
+
# Analyze inter-region transfers
|
|
798
|
+
if transfers['inter_region']['monthly_gb'] > 1000:
|
|
799
|
+
recommendations.append({
|
|
800
|
+
'type': 'region_consolidation',
|
|
801
|
+
'description': 'Consider consolidating resources in fewer regions',
|
|
802
|
+
'current_cost': transfers['inter_region']['monthly_cost'],
|
|
803
|
+
'potential_savings': transfers['inter_region']['monthly_cost'] * 0.8
|
|
804
|
+
})
|
|
805
|
+
|
|
806
|
+
# Analyze internet egress
|
|
807
|
+
if transfers['internet_egress']['monthly_gb'] > 10000:
|
|
808
|
+
recommendations.append({
|
|
809
|
+
'type': 'cdn_implementation',
|
|
810
|
+
'description': 'Implement CDN to reduce origin egress',
|
|
811
|
+
'current_cost': transfers['internet_egress']['monthly_cost'],
|
|
812
|
+
'potential_savings': transfers['internet_egress']['monthly_cost'] * 0.6
|
|
813
|
+
})
|
|
814
|
+
|
|
815
|
+
return {
|
|
816
|
+
'current_costs': transfers,
|
|
817
|
+
'recommendations': recommendations
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
def create_network_optimization_script(self):
|
|
821
|
+
"""Script to implement network optimizations"""
|
|
822
|
+
return '''
|
|
823
|
+
#!/usr/bin/env python3
|
|
824
|
+
import boto3
|
|
825
|
+
from collections import defaultdict
|
|
826
|
+
|
|
827
|
+
class NetworkOptimizer:
|
|
828
|
+
def __init__(self):
|
|
829
|
+
self.ec2 = boto3.client('ec2')
|
|
830
|
+
self.cloudwatch = boto3.client('cloudwatch')
|
|
831
|
+
|
|
832
|
+
def optimize_nat_gateways(self):
|
|
833
|
+
"""Consolidate and optimize NAT gateways"""
|
|
834
|
+
# Get all NAT gateways
|
|
835
|
+
nat_gateways = self.ec2.describe_nat_gateways()['NatGateways']
|
|
836
|
+
|
|
837
|
+
# Group by VPC
|
|
838
|
+
vpc_nat_gateways = defaultdict(list)
|
|
839
|
+
for nat in nat_gateways:
|
|
840
|
+
if nat['State'] == 'available':
|
|
841
|
+
vpc_nat_gateways[nat['VpcId']].append(nat)
|
|
842
|
+
|
|
843
|
+
optimizations = []
|
|
844
|
+
|
|
845
|
+
for vpc_id, nats in vpc_nat_gateways.items():
|
|
846
|
+
if len(nats) > 1:
|
|
847
|
+
# Check if consolidation is possible
|
|
848
|
+
traffic_analysis = self._analyze_nat_traffic(nats)
|
|
849
|
+
|
|
850
|
+
if traffic_analysis['can_consolidate']:
|
|
851
|
+
optimizations.append({
|
|
852
|
+
'vpc_id': vpc_id,
|
|
853
|
+
'action': 'consolidate_nat',
|
|
854
|
+
'current_count': len(nats),
|
|
855
|
+
'recommended_count': traffic_analysis['recommended_count'],
|
|
856
|
+
'monthly_savings': (len(nats) - traffic_analysis['recommended_count']) * 45
|
|
857
|
+
})
|
|
858
|
+
|
|
859
|
+
return optimizations
|
|
860
|
+
|
|
861
|
+
def implement_vpc_endpoints(self):
|
|
862
|
+
"""Implement VPC endpoints for AWS services"""
|
|
863
|
+
services_to_check = ['s3', 'dynamodb', 'ec2', 'sns', 'sqs']
|
|
864
|
+
vpc_list = self.ec2.describe_vpcs()['Vpcs']
|
|
865
|
+
|
|
866
|
+
implementations = []
|
|
867
|
+
|
|
868
|
+
for vpc in vpc_list:
|
|
869
|
+
vpc_id = vpc['VpcId']
|
|
870
|
+
|
|
871
|
+
# Check existing endpoints
|
|
872
|
+
existing = self._get_existing_endpoints(vpc_id)
|
|
873
|
+
|
|
874
|
+
for service in services_to_check:
|
|
875
|
+
if service not in existing:
|
|
876
|
+
# Check if service is being used
|
|
877
|
+
if self._is_service_used(vpc_id, service):
|
|
878
|
+
# Create VPC endpoint
|
|
879
|
+
endpoint = self._create_vpc_endpoint(vpc_id, service)
|
|
880
|
+
|
|
881
|
+
implementations.append({
|
|
882
|
+
'vpc_id': vpc_id,
|
|
883
|
+
'service': service,
|
|
884
|
+
'endpoint_id': endpoint['VpcEndpointId'],
|
|
885
|
+
'estimated_savings': self._estimate_endpoint_savings(vpc_id, service)
|
|
886
|
+
})
|
|
887
|
+
|
|
888
|
+
return implementations
|
|
889
|
+
|
|
890
|
+
def optimize_cloudfront_distribution(self):
|
|
891
|
+
"""Optimize CloudFront for cost reduction"""
|
|
892
|
+
cloudfront = boto3.client('cloudfront')
|
|
893
|
+
|
|
894
|
+
distributions = cloudfront.list_distributions()
|
|
895
|
+
optimizations = []
|
|
896
|
+
|
|
897
|
+
for dist in distributions.get('DistributionList', {}).get('Items', []):
|
|
898
|
+
# Analyze distribution patterns
|
|
899
|
+
analysis = self._analyze_distribution(dist['Id'])
|
|
900
|
+
|
|
901
|
+
if analysis['optimization_potential']:
|
|
902
|
+
optimizations.append({
|
|
903
|
+
'distribution_id': dist['Id'],
|
|
904
|
+
'recommendations': [
|
|
905
|
+
{
|
|
906
|
+
'action': 'adjust_price_class',
|
|
907
|
+
'current': dist['PriceClass'],
|
|
908
|
+
'recommended': analysis['recommended_price_class'],
|
|
909
|
+
'savings': analysis['price_class_savings']
|
|
910
|
+
},
|
|
911
|
+
{
|
|
912
|
+
'action': 'optimize_cache_behaviors',
|
|
913
|
+
'cache_improvements': analysis['cache_improvements'],
|
|
914
|
+
'savings': analysis['cache_savings']
|
|
915
|
+
}
|
|
916
|
+
]
|
|
917
|
+
})
|
|
918
|
+
|
|
919
|
+
return optimizations
|
|
920
|
+
'''
|
|
921
|
+
```
|
|
922
|
+
|
|
923
|
+
### 7. Container Cost Optimization
|
|
924
|
+
|
|
925
|
+
Optimize container workloads:
|
|
926
|
+
|
|
927
|
+
**Container Cost Optimizer**
|
|
928
|
+
```python
|
|
929
|
+
class ContainerCostOptimizer:
|
|
930
|
+
def optimize_ecs_costs(self):
|
|
931
|
+
"""Optimize ECS/Fargate costs"""
|
|
932
|
+
return {
|
|
933
|
+
'cluster_optimization': self._optimize_clusters(),
|
|
934
|
+
'task_rightsizing': self._rightsize_tasks(),
|
|
935
|
+
'scheduling_optimization': self._optimize_scheduling(),
|
|
936
|
+
'fargate_spot': self._implement_fargate_spot()
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
def _rightsize_tasks(self):
|
|
940
|
+
"""Rightsize ECS tasks"""
|
|
941
|
+
ecs = boto3.client('ecs')
|
|
942
|
+
cloudwatch = boto3.client('cloudwatch')
|
|
943
|
+
|
|
944
|
+
clusters = ecs.list_clusters()['clusterArns']
|
|
945
|
+
recommendations = []
|
|
946
|
+
|
|
947
|
+
for cluster in clusters:
|
|
948
|
+
# Get services
|
|
949
|
+
services = ecs.list_services(cluster=cluster)['serviceArns']
|
|
950
|
+
|
|
951
|
+
for service in services:
|
|
952
|
+
# Get task definition
|
|
953
|
+
service_detail = ecs.describe_services(
|
|
954
|
+
cluster=cluster,
|
|
955
|
+
services=[service]
|
|
956
|
+
)['services'][0]
|
|
957
|
+
|
|
958
|
+
task_def = service_detail['taskDefinition']
|
|
959
|
+
|
|
960
|
+
# Analyze resource utilization
|
|
961
|
+
utilization = self._analyze_task_utilization(cluster, service)
|
|
962
|
+
|
|
963
|
+
# Generate recommendations
|
|
964
|
+
if utilization['cpu']['average'] < 30 or utilization['memory']['average'] < 40:
|
|
965
|
+
recommendations.append({
|
|
966
|
+
'cluster': cluster,
|
|
967
|
+
'service': service,
|
|
968
|
+
'current_cpu': service_detail['cpu'],
|
|
969
|
+
'current_memory': service_detail['memory'],
|
|
970
|
+
'recommended_cpu': int(service_detail['cpu'] * 0.7),
|
|
971
|
+
'recommended_memory': int(service_detail['memory'] * 0.8),
|
|
972
|
+
'monthly_savings': self._calculate_task_savings(
|
|
973
|
+
service_detail,
|
|
974
|
+
utilization
|
|
975
|
+
)
|
|
976
|
+
})
|
|
977
|
+
|
|
978
|
+
return recommendations
|
|
979
|
+
|
|
980
|
+
def create_k8s_cost_optimization(self):
|
|
981
|
+
"""Kubernetes cost optimization"""
|
|
982
|
+
return '''
|
|
983
|
+
apiVersion: v1
|
|
984
|
+
kind: ConfigMap
|
|
985
|
+
metadata:
|
|
986
|
+
name: cost-optimization-config
|
|
987
|
+
data:
|
|
988
|
+
vertical-pod-autoscaler.yaml: |
|
|
989
|
+
apiVersion: autoscaling.k8s.io/v1
|
|
990
|
+
kind: VerticalPodAutoscaler
|
|
991
|
+
metadata:
|
|
992
|
+
name: app-vpa
|
|
993
|
+
spec:
|
|
994
|
+
targetRef:
|
|
995
|
+
apiVersion: apps/v1
|
|
996
|
+
kind: Deployment
|
|
997
|
+
name: app-deployment
|
|
998
|
+
updatePolicy:
|
|
999
|
+
updateMode: "Auto"
|
|
1000
|
+
resourcePolicy:
|
|
1001
|
+
containerPolicies:
|
|
1002
|
+
- containerName: app
|
|
1003
|
+
minAllowed:
|
|
1004
|
+
cpu: 100m
|
|
1005
|
+
memory: 128Mi
|
|
1006
|
+
maxAllowed:
|
|
1007
|
+
cpu: 2
|
|
1008
|
+
memory: 2Gi
|
|
1009
|
+
|
|
1010
|
+
cluster-autoscaler-config.yaml: |
|
|
1011
|
+
apiVersion: apps/v1
|
|
1012
|
+
kind: Deployment
|
|
1013
|
+
metadata:
|
|
1014
|
+
name: cluster-autoscaler
|
|
1015
|
+
spec:
|
|
1016
|
+
template:
|
|
1017
|
+
spec:
|
|
1018
|
+
containers:
|
|
1019
|
+
- image: k8s.gcr.io/autoscaling/cluster-autoscaler:v1.21.0
|
|
1020
|
+
name: cluster-autoscaler
|
|
1021
|
+
command:
|
|
1022
|
+
- ./cluster-autoscaler
|
|
1023
|
+
- --v=4
|
|
1024
|
+
- --stderrthreshold=info
|
|
1025
|
+
- --cloud-provider=aws
|
|
1026
|
+
- --skip-nodes-with-local-storage=false
|
|
1027
|
+
- --expander=priority
|
|
1028
|
+
- --node-group-auto-discovery=asg:tag=k8s.io/cluster-autoscaler/enabled,k8s.io/cluster-autoscaler/cluster-name
|
|
1029
|
+
- --scale-down-enabled=true
|
|
1030
|
+
- --scale-down-unneeded-time=10m
|
|
1031
|
+
- --scale-down-utilization-threshold=0.5
|
|
1032
|
+
|
|
1033
|
+
spot-instance-handler.yaml: |
|
|
1034
|
+
apiVersion: apps/v1
|
|
1035
|
+
kind: DaemonSet
|
|
1036
|
+
metadata:
|
|
1037
|
+
name: aws-node-termination-handler
|
|
1038
|
+
spec:
|
|
1039
|
+
selector:
|
|
1040
|
+
matchLabels:
|
|
1041
|
+
app: aws-node-termination-handler
|
|
1042
|
+
template:
|
|
1043
|
+
spec:
|
|
1044
|
+
containers:
|
|
1045
|
+
- name: aws-node-termination-handler
|
|
1046
|
+
image: amazon/aws-node-termination-handler:v1.13.0
|
|
1047
|
+
env:
|
|
1048
|
+
- name: NODE_NAME
|
|
1049
|
+
valueFrom:
|
|
1050
|
+
fieldRef:
|
|
1051
|
+
fieldPath: spec.nodeName
|
|
1052
|
+
- name: ENABLE_SPOT_INTERRUPTION_DRAINING
|
|
1053
|
+
value: "true"
|
|
1054
|
+
- name: ENABLE_SCHEDULED_EVENT_DRAINING
|
|
1055
|
+
value: "true"
|
|
1056
|
+
'''
|
|
1057
|
+
```
|
|
1058
|
+
|
|
1059
|
+
### 8. Serverless Cost Optimization
|
|
1060
|
+
|
|
1061
|
+
Optimize serverless workloads:
|
|
1062
|
+
|
|
1063
|
+
**Serverless Optimizer**
|
|
1064
|
+
```python
|
|
1065
|
+
class ServerlessOptimizer:
|
|
1066
|
+
def optimize_lambda_costs(self):
|
|
1067
|
+
"""Optimize Lambda function costs"""
|
|
1068
|
+
lambda_client = boto3.client('lambda')
|
|
1069
|
+
cloudwatch = boto3.client('cloudwatch')
|
|
1070
|
+
|
|
1071
|
+
functions = lambda_client.list_functions()['Functions']
|
|
1072
|
+
optimizations = []
|
|
1073
|
+
|
|
1074
|
+
for function in functions:
|
|
1075
|
+
# Analyze function performance
|
|
1076
|
+
analysis = self._analyze_lambda_function(function)
|
|
1077
|
+
|
|
1078
|
+
# Memory optimization
|
|
1079
|
+
if analysis['memory_optimization_possible']:
|
|
1080
|
+
optimizations.append({
|
|
1081
|
+
'function_name': function['FunctionName'],
|
|
1082
|
+
'type': 'memory_optimization',
|
|
1083
|
+
'current_memory': function['MemorySize'],
|
|
1084
|
+
'recommended_memory': analysis['optimal_memory'],
|
|
1085
|
+
'estimated_savings': analysis['memory_savings']
|
|
1086
|
+
})
|
|
1087
|
+
|
|
1088
|
+
# Timeout optimization
|
|
1089
|
+
if analysis['timeout_optimization_possible']:
|
|
1090
|
+
optimizations.append({
|
|
1091
|
+
'function_name': function['FunctionName'],
|
|
1092
|
+
'type': 'timeout_optimization',
|
|
1093
|
+
'current_timeout': function['Timeout'],
|
|
1094
|
+
'recommended_timeout': analysis['optimal_timeout'],
|
|
1095
|
+
'risk_reduction': 'prevents unnecessary charges from hanging functions'
|
|
1096
|
+
})
|
|
1097
|
+
|
|
1098
|
+
return optimizations
|
|
1099
|
+
|
|
1100
|
+
def implement_lambda_cost_controls(self):
|
|
1101
|
+
"""Implement Lambda cost controls"""
|
|
1102
|
+
return '''
|
|
1103
|
+
import json
|
|
1104
|
+
import boto3
|
|
1105
|
+
from datetime import datetime
|
|
1106
|
+
|
|
1107
|
+
def lambda_cost_controller(event, context):
|
|
1108
|
+
"""Lambda function to monitor and control Lambda costs"""
|
|
1109
|
+
|
|
1110
|
+
cloudwatch = boto3.client('cloudwatch')
|
|
1111
|
+
lambda_client = boto3.client('lambda')
|
|
1112
|
+
|
|
1113
|
+
# Get current month costs
|
|
1114
|
+
costs = get_current_month_lambda_costs()
|
|
1115
|
+
|
|
1116
|
+
# Check against budget
|
|
1117
|
+
budget_limit = float(os.environ.get('MONTHLY_BUDGET', '1000'))
|
|
1118
|
+
|
|
1119
|
+
if costs > budget_limit * 0.8: # 80% of budget
|
|
1120
|
+
# Implement cost controls
|
|
1121
|
+
high_cost_functions = identify_high_cost_functions()
|
|
1122
|
+
|
|
1123
|
+
for func in high_cost_functions:
|
|
1124
|
+
# Reduce concurrency
|
|
1125
|
+
lambda_client.put_function_concurrency(
|
|
1126
|
+
FunctionName=func['FunctionName'],
|
|
1127
|
+
ReservedConcurrentExecutions=max(
|
|
1128
|
+
1,
|
|
1129
|
+
int(func['CurrentConcurrency'] * 0.5)
|
|
1130
|
+
)
|
|
1131
|
+
)
|
|
1132
|
+
|
|
1133
|
+
# Alert
|
|
1134
|
+
send_cost_alert(func, costs, budget_limit)
|
|
1135
|
+
|
|
1136
|
+
# Implement provisioned concurrency optimization
|
|
1137
|
+
optimize_provisioned_concurrency()
|
|
1138
|
+
|
|
1139
|
+
return {
|
|
1140
|
+
'statusCode': 200,
|
|
1141
|
+
'body': json.dumps({
|
|
1142
|
+
'current_costs': costs,
|
|
1143
|
+
'budget_limit': budget_limit,
|
|
1144
|
+
'actions_taken': len(high_cost_functions)
|
|
1145
|
+
})
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
def optimize_provisioned_concurrency():
|
|
1149
|
+
"""Optimize provisioned concurrency based on usage patterns"""
|
|
1150
|
+
functions = get_functions_with_provisioned_concurrency()
|
|
1151
|
+
|
|
1152
|
+
for func in functions:
|
|
1153
|
+
# Analyze invocation patterns
|
|
1154
|
+
patterns = analyze_invocation_patterns(func['FunctionName'])
|
|
1155
|
+
|
|
1156
|
+
if patterns['predictable']:
|
|
1157
|
+
# Schedule provisioned concurrency
|
|
1158
|
+
create_scheduled_scaling(
|
|
1159
|
+
func['FunctionName'],
|
|
1160
|
+
patterns['peak_hours'],
|
|
1161
|
+
patterns['peak_concurrency']
|
|
1162
|
+
)
|
|
1163
|
+
else:
|
|
1164
|
+
# Consider removing provisioned concurrency
|
|
1165
|
+
if patterns['avg_cold_starts'] < 10: # per minute
|
|
1166
|
+
remove_provisioned_concurrency(func['FunctionName'])
|
|
1167
|
+
'''
|
|
1168
|
+
```
|
|
1169
|
+
|
|
1170
|
+
### 9. Cost Allocation and Tagging
|
|
1171
|
+
|
|
1172
|
+
Implement cost allocation strategies:
|
|
1173
|
+
|
|
1174
|
+
**Cost Allocation Manager**
|
|
1175
|
+
```python
|
|
1176
|
+
class CostAllocationManager:
|
|
1177
|
+
def implement_tagging_strategy(self):
|
|
1178
|
+
"""Implement comprehensive tagging strategy"""
|
|
1179
|
+
return {
|
|
1180
|
+
'required_tags': [
|
|
1181
|
+
{'key': 'Environment', 'values': ['prod', 'staging', 'dev', 'test']},
|
|
1182
|
+
{'key': 'CostCenter', 'values': 'dynamic'},
|
|
1183
|
+
{'key': 'Project', 'values': 'dynamic'},
|
|
1184
|
+
{'key': 'Owner', 'values': 'dynamic'},
|
|
1185
|
+
{'key': 'Department', 'values': 'dynamic'}
|
|
1186
|
+
],
|
|
1187
|
+
'automation': self._create_tagging_automation(),
|
|
1188
|
+
'enforcement': self._create_tag_enforcement(),
|
|
1189
|
+
'reporting': self._create_cost_allocation_reports()
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
def _create_tagging_automation(self):
|
|
1193
|
+
"""Automate resource tagging"""
|
|
1194
|
+
return '''
|
|
1195
|
+
import boto3
|
|
1196
|
+
from datetime import datetime
|
|
1197
|
+
|
|
1198
|
+
class AutoTagger:
|
|
1199
|
+
def __init__(self):
|
|
1200
|
+
self.tag_policies = self.load_tag_policies()
|
|
1201
|
+
|
|
1202
|
+
def auto_tag_resources(self, event, context):
|
|
1203
|
+
"""Auto-tag resources on creation"""
|
|
1204
|
+
|
|
1205
|
+
# Parse CloudTrail event
|
|
1206
|
+
detail = event['detail']
|
|
1207
|
+
event_name = detail['eventName']
|
|
1208
|
+
|
|
1209
|
+
# Map events to resource types
|
|
1210
|
+
if event_name.startswith('Create'):
|
|
1211
|
+
resource_arn = self.extract_resource_arn(detail)
|
|
1212
|
+
|
|
1213
|
+
if resource_arn:
|
|
1214
|
+
# Determine tags
|
|
1215
|
+
tags = self.determine_tags(detail)
|
|
1216
|
+
|
|
1217
|
+
# Apply tags
|
|
1218
|
+
self.apply_tags(resource_arn, tags)
|
|
1219
|
+
|
|
1220
|
+
# Log tagging action
|
|
1221
|
+
self.log_tagging(resource_arn, tags)
|
|
1222
|
+
|
|
1223
|
+
def determine_tags(self, event_detail):
|
|
1224
|
+
"""Determine tags based on context"""
|
|
1225
|
+
tags = []
|
|
1226
|
+
|
|
1227
|
+
# User-based tags
|
|
1228
|
+
user_identity = event_detail.get('userIdentity', {})
|
|
1229
|
+
if 'userName' in user_identity:
|
|
1230
|
+
tags.append({
|
|
1231
|
+
'Key': 'Creator',
|
|
1232
|
+
'Value': user_identity['userName']
|
|
1233
|
+
})
|
|
1234
|
+
|
|
1235
|
+
# Time-based tags
|
|
1236
|
+
tags.append({
|
|
1237
|
+
'Key': 'CreatedDate',
|
|
1238
|
+
'Value': datetime.now().strftime('%Y-%m-%d')
|
|
1239
|
+
})
|
|
1240
|
+
|
|
1241
|
+
# Environment inference
|
|
1242
|
+
if 'prod' in event_detail.get('sourceIPAddress', ''):
|
|
1243
|
+
env = 'prod'
|
|
1244
|
+
elif 'dev' in event_detail.get('sourceIPAddress', ''):
|
|
1245
|
+
env = 'dev'
|
|
1246
|
+
else:
|
|
1247
|
+
env = 'unknown'
|
|
1248
|
+
|
|
1249
|
+
tags.append({
|
|
1250
|
+
'Key': 'Environment',
|
|
1251
|
+
'Value': env
|
|
1252
|
+
})
|
|
1253
|
+
|
|
1254
|
+
return tags
|
|
1255
|
+
|
|
1256
|
+
def create_cost_allocation_dashboard(self):
|
|
1257
|
+
"""Create cost allocation dashboard"""
|
|
1258
|
+
return """
|
|
1259
|
+
SELECT
|
|
1260
|
+
tags.environment,
|
|
1261
|
+
tags.department,
|
|
1262
|
+
tags.project,
|
|
1263
|
+
SUM(costs.amount) as total_cost,
|
|
1264
|
+
SUM(costs.amount) / SUM(SUM(costs.amount)) OVER () * 100 as percentage
|
|
1265
|
+
FROM
|
|
1266
|
+
aws_costs costs
|
|
1267
|
+
JOIN
|
|
1268
|
+
resource_tags tags ON costs.resource_id = tags.resource_id
|
|
1269
|
+
WHERE
|
|
1270
|
+
costs.date >= DATE_TRUNC('month', CURRENT_DATE)
|
|
1271
|
+
GROUP BY
|
|
1272
|
+
tags.environment,
|
|
1273
|
+
tags.department,
|
|
1274
|
+
tags.project
|
|
1275
|
+
ORDER BY
|
|
1276
|
+
total_cost DESC
|
|
1277
|
+
"""
|
|
1278
|
+
'''
|
|
1279
|
+
```
|
|
1280
|
+
|
|
1281
|
+
### 10. Cost Monitoring and Alerts
|
|
1282
|
+
|
|
1283
|
+
Implement proactive cost monitoring:
|
|
1284
|
+
|
|
1285
|
+
**Cost Monitoring System**
|
|
1286
|
+
```python
|
|
1287
|
+
class CostMonitoringSystem:
|
|
1288
|
+
def setup_cost_alerts(self):
|
|
1289
|
+
"""Setup comprehensive cost alerting"""
|
|
1290
|
+
alerts = []
|
|
1291
|
+
|
|
1292
|
+
# Budget alerts
|
|
1293
|
+
alerts.extend(self._create_budget_alerts())
|
|
1294
|
+
|
|
1295
|
+
# Anomaly detection
|
|
1296
|
+
alerts.extend(self._create_anomaly_alerts())
|
|
1297
|
+
|
|
1298
|
+
# Threshold alerts
|
|
1299
|
+
alerts.extend(self._create_threshold_alerts())
|
|
1300
|
+
|
|
1301
|
+
# Forecast alerts
|
|
1302
|
+
alerts.extend(self._create_forecast_alerts())
|
|
1303
|
+
|
|
1304
|
+
return alerts
|
|
1305
|
+
|
|
1306
|
+
def _create_anomaly_alerts(self):
|
|
1307
|
+
"""Create anomaly detection alerts"""
|
|
1308
|
+
ce = boto3.client('ce')
|
|
1309
|
+
|
|
1310
|
+
# Create anomaly monitor
|
|
1311
|
+
monitor = ce.create_anomaly_monitor(
|
|
1312
|
+
AnomalyMonitor={
|
|
1313
|
+
'MonitorName': 'ServiceCostMonitor',
|
|
1314
|
+
'MonitorType': 'DIMENSIONAL',
|
|
1315
|
+
'MonitorDimension': 'SERVICE'
|
|
1316
|
+
}
|
|
1317
|
+
)
|
|
1318
|
+
|
|
1319
|
+
# Create anomaly subscription
|
|
1320
|
+
subscription = ce.create_anomaly_subscription(
|
|
1321
|
+
AnomalySubscription={
|
|
1322
|
+
'SubscriptionName': 'CostAnomalyAlerts',
|
|
1323
|
+
'Threshold': 100.0, # Alert on anomalies > $100
|
|
1324
|
+
'Frequency': 'DAILY',
|
|
1325
|
+
'MonitorArnList': [monitor['MonitorArn']],
|
|
1326
|
+
'Subscribers': [
|
|
1327
|
+
{
|
|
1328
|
+
'Type': 'EMAIL',
|
|
1329
|
+
'Address': 'team@company.com'
|
|
1330
|
+
},
|
|
1331
|
+
{
|
|
1332
|
+
'Type': 'SNS',
|
|
1333
|
+
'Address': 'arn:aws:sns:us-east-1:123456789012:cost-alerts'
|
|
1334
|
+
}
|
|
1335
|
+
]
|
|
1336
|
+
}
|
|
1337
|
+
)
|
|
1338
|
+
|
|
1339
|
+
return [monitor, subscription]
|
|
1340
|
+
|
|
1341
|
+
def create_cost_dashboard(self):
|
|
1342
|
+
"""Create executive cost dashboard"""
|
|
1343
|
+
return '''
|
|
1344
|
+
<!DOCTYPE html>
|
|
1345
|
+
<html>
|
|
1346
|
+
<head>
|
|
1347
|
+
<title>Cloud Cost Dashboard</title>
|
|
1348
|
+
<script src="https://d3js.org/d3.v7.min.js"></script>
|
|
1349
|
+
<style>
|
|
1350
|
+
.metric-card {
|
|
1351
|
+
background: #f5f5f5;
|
|
1352
|
+
padding: 20px;
|
|
1353
|
+
margin: 10px;
|
|
1354
|
+
border-radius: 8px;
|
|
1355
|
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
1356
|
+
}
|
|
1357
|
+
.alert { color: #d32f2f; }
|
|
1358
|
+
.warning { color: #f57c00; }
|
|
1359
|
+
.success { color: #388e3c; }
|
|
1360
|
+
</style>
|
|
1361
|
+
</head>
|
|
1362
|
+
<body>
|
|
1363
|
+
<div id="dashboard">
|
|
1364
|
+
<h1>Cloud Cost Optimization Dashboard</h1>
|
|
1365
|
+
|
|
1366
|
+
<div class="summary-row">
|
|
1367
|
+
<div class="metric-card">
|
|
1368
|
+
<h3>Current Month Spend</h3>
|
|
1369
|
+
<div class="metric">${current_spend}</div>
|
|
1370
|
+
<div class="trend ${spend_trend_class}">${spend_trend}% vs last month</div>
|
|
1371
|
+
</div>
|
|
1372
|
+
|
|
1373
|
+
<div class="metric-card">
|
|
1374
|
+
<h3>Projected Month End</h3>
|
|
1375
|
+
<div class="metric">${projected_spend}</div>
|
|
1376
|
+
<div class="budget-status">Budget: ${budget}</div>
|
|
1377
|
+
</div>
|
|
1378
|
+
|
|
1379
|
+
<div class="metric-card">
|
|
1380
|
+
<h3>Optimization Opportunities</h3>
|
|
1381
|
+
<div class="metric">${total_savings_identified}</div>
|
|
1382
|
+
<div class="count">{opportunity_count} recommendations</div>
|
|
1383
|
+
</div>
|
|
1384
|
+
|
|
1385
|
+
<div class="metric-card">
|
|
1386
|
+
<h3>Realized Savings</h3>
|
|
1387
|
+
<div class="metric">${realized_savings_mtd}</div>
|
|
1388
|
+
<div class="count">YTD: ${realized_savings_ytd}</div>
|
|
1389
|
+
</div>
|
|
1390
|
+
</div>
|
|
1391
|
+
|
|
1392
|
+
<div class="charts-row">
|
|
1393
|
+
<div id="spend-trend-chart"></div>
|
|
1394
|
+
<div id="service-breakdown-chart"></div>
|
|
1395
|
+
<div id="optimization-progress-chart"></div>
|
|
1396
|
+
</div>
|
|
1397
|
+
|
|
1398
|
+
<div class="recommendations-section">
|
|
1399
|
+
<h2>Top Optimization Recommendations</h2>
|
|
1400
|
+
<table id="recommendations-table">
|
|
1401
|
+
<thead>
|
|
1402
|
+
<tr>
|
|
1403
|
+
<th>Priority</th>
|
|
1404
|
+
<th>Service</th>
|
|
1405
|
+
<th>Recommendation</th>
|
|
1406
|
+
<th>Monthly Savings</th>
|
|
1407
|
+
<th>Effort</th>
|
|
1408
|
+
<th>Action</th>
|
|
1409
|
+
</tr>
|
|
1410
|
+
</thead>
|
|
1411
|
+
<tbody>
|
|
1412
|
+
${recommendation_rows}
|
|
1413
|
+
</tbody>
|
|
1414
|
+
</table>
|
|
1415
|
+
</div>
|
|
1416
|
+
</div>
|
|
1417
|
+
|
|
1418
|
+
<script>
|
|
1419
|
+
// Real-time updates
|
|
1420
|
+
setInterval(updateDashboard, 60000);
|
|
1421
|
+
|
|
1422
|
+
// Initialize charts
|
|
1423
|
+
initializeCharts();
|
|
1424
|
+
</script>
|
|
1425
|
+
</body>
|
|
1426
|
+
</html>
|
|
1427
|
+
'''
|
|
1428
|
+
```
|
|
1429
|
+
|
|
1430
|
+
## Output Format
|
|
1431
|
+
|
|
1432
|
+
1. **Cost Analysis Report**: Comprehensive breakdown of current cloud costs
|
|
1433
|
+
2. **Optimization Recommendations**: Prioritized list of cost-saving opportunities
|
|
1434
|
+
3. **Implementation Scripts**: Automated scripts for implementing optimizations
|
|
1435
|
+
4. **Monitoring Dashboards**: Real-time cost tracking and alerting
|
|
1436
|
+
5. **ROI Calculations**: Detailed savings projections and payback periods
|
|
1437
|
+
6. **Risk Assessment**: Analysis of risks associated with each optimization
|
|
1438
|
+
7. **Implementation Roadmap**: Phased approach to cost optimization
|
|
1439
|
+
8. **Best Practices Guide**: Long-term cost management strategies
|
|
1440
|
+
|
|
1441
|
+
Focus on delivering immediate cost savings while establishing sustainable cost optimization practices that maintain performance and reliability standards.
|