Cleanup stacks

  1. Go to the terminal window in Cloud9.

  2. Remove the locally deployed api stack by running the following command and following the prompts:

    sam delete
    
  3. Remove the Prod stack that were deployed by CodePipeline

    sam delete --stack-name api-prod-stack
    
  4. Remove the Dev stacks that were deployed by CodePipeline

    sam delete --stack-name api-dev-stack
    
  5. Remove the CodePipeline stack by running the following command and following the prompts:

    sam delete --stack-name api-pipeline-stack
    

    PLEASE NOTE: an error will occur while deleting the stack. This is known, and can be skipped for now. If you wish to continue, remove the CodeBuild role manually, create a new CloudFormation execution role with the same name associated with the CloudFormation stack (i.e. api-pipeline-stack-PipelineStackCloudFormationExec-0123456789AB), but with appropriate access (AdministratorAccess policy will do for this demo to temporarily delete the stack), then delete the execution role.

  6. Remove the SAM pipeline stack by running the following command and following the prompts:

    sam delete --stack-name aws-sam-cli-managed-prod-pipeline-resources
    
    sam delete --stack-name aws-sam-cli-managed-dev-pipeline-resources
    
  7. Remove the repository

    aws codecommit delete-repository --repository-name api
    
  8. Delete the S3 buckets that were not deleted. You can use the following python code to delete the bucket including versioned buckets.

    #!/usr/bin/env python
    
    BUCKET = 'ENTER_BUCKET_NAME'
       
    import boto3
       
    s3 = boto3.resource('s3')
    bucket = s3.Bucket(BUCKET)
    bucket.object_versions.delete()
       
    bucket.delete()
    
  9. Go to Cloud9, select the environment and delete it.