1. Prepare Your CloudFormation Template
Ensure your CloudFormation template file (e.g., budget-notification.yaml
) includes the IAM Role, Lambda Function, SNS Topic, Event Rule, and permissions.
2. Install and Configure AWS CLI
Ensure the AWS CLI is installed and configured with credentials for the new AWS account. Use the following commands to configure it:
aws configure
Enter your new AWS account credentials and default region when prompted.
3. Create the CloudFormation Stack
Deploy the CloudFormation stack using the AWS CLI with the following command:
aws cloudformation create-stack --stack-name BudgetNotificationStack --template-body file://budget-notification.yaml --capabilities CAPABILITY_NAMED_IAM
4. Verify the Stack Creation
Check the status of the stack to ensure it's created successfully:
aws cloudformation describe-stacks --stack-name BudgetNotificationStack
5. Create a Budget in AWS Budgets
You’ll need to create a budget that matches the name used in the Lambda function (MyDailyBudget9
). Here’s a sample command to create a budget using the AWS CLI:
aws budgets create-budget --account-id <your-account-id> --budget "{\"BudgetName\":\"MyDailyBudget9\",\"BudgetLimit\":{\"Amount\":\"300.0\",\"Unit\":\"USD\"},\"CostFilters\":{},\"CostTypes\":{\"IncludeTax\":true,\"IncludeSubscription\":true,\"UseBlended\":false,\"IncludeRefund\":true,\"IncludeCredit\":true,\"IncludeUpfront\":true,\"IncludeRecurring\":true,\"IncludeOtherSubscription\":true,\"IncludeSupport\":true,\"IncludeDiscount\":true,\"UseAmortized\":false},\"TimeUnit\":\"DAILY\",\"BudgetType\":\"COST\"}"
Replace <your-account-id>
with your new AWS account ID.
6. Verify Budget Creation
Ensure the budget is created by listing budgets:
aws budgets describe-budgets --account-id <your-account-id>
7. Confirm SNS Email Subscriptions
After creating the stack, check the SNS Topic subscriptions to confirm that the email addresses have been added. You should receive an email asking you to confirm the subscription. Follow the link in the email to confirm.
List SNS topics to find the topic ARN:
aws sns list-topics
List subscriptions to verify:
aws sns list-subscriptions
8. Verify Lambda Function Execution
Test the Lambda function to ensure it’s triggered correctly. You can manually invoke the Lambda function to verify it works:
aws lambda invoke --function-name DailyBudgetReportFunction output.txt
Check the output in output.txt
and the CloudWatch Logs for any errors.
Summary of Commands
- Deploy Stack:
aws cloudformation create-stack --stack-name BudgetNotificationStack --template-body file://budget-notification.yaml --capabilities CAPABILITY_NAMED_IAM
- Check Stack Status:
aws cloudformation describe-stacks --stack-name BudgetNotificationStack
- Create Budget:
aws budgets create-budget --account-id <your-account-id> --budget "{\"BudgetName\":\"MyDailyBudget9\",\"BudgetLimit\":{\"Amount\":\"300.0\",\"Unit\":\"USD\"},\"CostFilters\":{},\"CostTypes\":{\"IncludeTax\":true,\"IncludeSubscription\":true,\"UseBlended\":false,\"IncludeRefund\":true,\"IncludeCredit\":true,\"IncludeUpfront\":true,\"IncludeRecurring\":true,\"IncludeOtherSubscription\":true,\"IncludeSupport\":true,\"IncludeDiscount\":true,\"UseAmortized\":false},\"TimeUnit\":\"DAILY\",\"BudgetType\":\"COST\"}"
- List Budgets:
aws budgets describe-budgets --account-id <your-account-id>
- List SNS Topics:
aws sns list-topics
- List SNS Subscriptions:
aws sns list-subscriptions
- Invoke Lambda Function:
aws lambda invoke --function-name DailyBudgetReportFunction output.txt
Following these steps will set up the CloudFormation stack, create the required budget, and ensure that the Lambda function and SNS notifications are correctly configured.
Top comments (0)