# CloudFormation capstone lab

The capstone provisions one Amazon SQS queue in a sandbox account. It has no consumer, public endpoint or IAM resource. CloudFormation itself has no additional charge; SQS usage is subject to AWS pricing, so delete the stack after the exercise.

## Prerequisites

- AWS CLI v2 and a named sandbox profile.
- Permission to create, describe and delete a CloudFormation stack and SQS queue.
- Confirm the target account and Region before each command.

## Review, create and execute

From this directory, validate the template:

```bash
aws sts get-caller-identity --profile sandbox
aws cloudformation validate-template --template-body file://template.yaml --profile sandbox --region us-east-1
```

Create a change set, then inspect it before execution:

```bash
aws cloudformation create-change-set \
  --stack-name cfn-capstone \
  --change-set-name initial-review \
  --change-set-type CREATE \
  --template-body file://template.yaml \
  --parameters ParameterKey=Environment,ParameterValue=dev ParameterKey=VisibilityTimeout,ParameterValue=30 \
  --profile sandbox --region us-east-1

aws cloudformation describe-change-set \
  --stack-name cfn-capstone --change-set-name initial-review \
  --profile sandbox --region us-east-1
```

Confirm the change set creates only `CourseQueue`, uses the expected parameter values and does not request replacement or deletion. Execute it:

```bash
aws cloudformation execute-change-set \
  --stack-name cfn-capstone --change-set-name initial-review \
  --profile sandbox --region us-east-1

aws cloudformation wait stack-create-complete \
  --stack-name cfn-capstone --profile sandbox --region us-east-1
aws cloudformation describe-stacks \
  --stack-name cfn-capstone --query 'Stacks[0].{Status:StackStatus,Outputs:Outputs}' \
  --profile sandbox --region us-east-1
```

## Observe drift and clean up

Change `VisibilityTimeout` manually in the SQS console, then run drift detection and inspect the resource-level result. Drift detection only checks supported properties that CloudFormation tracks.

```bash
drift_id=$(aws cloudformation detect-stack-drift --stack-name cfn-capstone --query StackDriftDetectionId --output text --profile sandbox --region us-east-1)
aws cloudformation describe-stack-drift-detection-status --stack-drift-detection-id "$drift_id" --profile sandbox --region us-east-1
aws cloudformation describe-stack-resource-drifts --stack-name cfn-capstone --profile sandbox --region us-east-1
```

If the detection status is still `DETECTION_IN_PROGRESS`, poll the status command until it is complete before requesting the resource-level drift report.

Restore the template as the source of truth with a reviewed update, or simply delete the lab stack:

```bash
aws cloudformation delete-stack --stack-name cfn-capstone --profile sandbox --region us-east-1
aws cloudformation wait stack-delete-complete --stack-name cfn-capstone --profile sandbox --region us-east-1
```

Do not run the commands against a shared or production account.
