# aws-account-closure-notifier The template for the solution stack will deploy the `IAM roles`, `EventBridge Rules`, `Lambda functions`, and the `SNS Topic`. This Stack deploys the solution for `aws-account-closure-notifier`, where the deployed AWS Lambda function `aws-account-closure-notifier-lambda`is configured with `AWS EventBridge Rule` as Invocation Source. This is configured to trigger the Lambda Function when `CloseAccount` or `RemoveAccountFromOrganization` API call is been made. Further the Lambda Function processes the event and send `SNS Notification` and if enabled it also send Slack Notification to the Target Webbook ## How To Deploy | Steps | Description | |-----------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | __Launch the CloudFormation template for the solution stack__ | The template for the solution stack will deploy the IAM roles, EventBridge Rules, Lambda functions, and the SNS Topic.

Open the AWS Management console for the AWS Organizations Management account, chose the us-east-1 region and then open the CloudFormation console. Create the stack by using the __account-closure-notifier.yml__ template and the following values:

__Stack name__ – aws-account-closure-notifier-stack
__ResourcePrefix parameter__ – aws-account-closure-notifier
__SlackNotification parameter__ – If Slack notifications are required, change this to "true"
__SlackWebhookEndpoint parameter__ – If Slack notifications are required, set the WebHook URL here | | __Verify that the solution has launched successfully__ | Wait for the CloudFormation stack to reach a status of __CREATE_COMPLETE__. Open the EventBridge console in us-east-1, and verify that a new Rule has been created with the name __aws-account-closure-notifier-event-rule.__ | | __(optional) Subscribe to the SNS Topic__ | Open the Amazon SNS console in us-east-1, find the Topic named __aws-account-closure-notifier-sns-topic__.
Click the Topic name and select __Create Subscription__. Chose a __Protocol__ of Email and then enter an __Endpoint__ containing an appropriate email address.
Once the Subscription has been created, wait for the verification email to arrive - click the verify link in this email to confirm the subscription.Topic | ## How To Test | Steps | Description | |------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | __Send a test event to the default Event bus__ | Open the Amazon EventBridge console in us-east-1, select the __default__ Event bus.
Press the Send events button.
Set the Event Source to account.closure.notifier and the Detail Type to AWS API Call via CloudTrail.
Copy and paste the contents of `tests/dummy-event.json` into the Event Detail section.
Press the Send button to trigger the notification workflow. | | __Verify that the email notification was received__ | Check the mailbox which subscribed to the SNS Topic for notifications, an email should be received shortly with details of the account which was closed and principal which performed the API call. | | __(optional) Verify that the Slack notification was received__ | Check the Slack channel which is mapped to the WebHook, a message should be received within a minute with details of the account which was closed and principal which performed the API call. |