15

Follow the read for an example it says:

# AWS SAM Hello World Example #

A simple AWS SAM template that specifies a single Lambda function.

## Usage ##

To create and deploy the SAM Hello World example, first ensure that you've met the requirements described in the [root README](../../README.md). Then
follow the steps below.

### Test your application locally ###

Use [SAM Local](https://github.com/awslabs/aws-sam-local) to run your Lambda function locally:

    sam local invoke "HelloWorldFunction" -e event.json

### Package artifacts ###

Run the following command, replacing `BUCKET-NAME` with the name of your bucket:

    sam package --template-file template.yaml --s3-bucket BUCKET-NAME --output-template-file packaged-template.yaml

This creates a new template file, packaged-template.yaml, that you will use to deploy your serverless application.

### Deploy to AWS CloudFormation ###

Run the following command, replacing `MY-NEW-STACK` with a name for your CloudFormation stack.

    sam deploy --template-file packaged-template.yaml --stack-name MY-NEW-STACK --capabilities CAPABILITY_IAM

This uploads your template to an S3 bucket and deploys the specified resources using AWS CloudFormation.

Now what is the sam local command to delete the whole stack including s3 bucket and CF stack?

red888
  • 27,709
  • 55
  • 204
  • 392

1 Answers1

30

Edit for 2022:

Sam cli now has a delete command can see official docs here. Should be able run like this now:

sam delete --stack-name MY-NEW-STACK

Thanks @jesusnoseq for pointer to update .


Legacy 2018 Answer

There is currently no sam command to delete all of these resources. You would just use the relevant aws cli commands which sam-cli is just a wrapper around anyways. Example to delete you CFN stack.

aws cloudformation delete-stack --stack-name MY-NEW-STACK

Ellery
  • 1,356
  • 1
  • 14
  • 22
  • 1
    You can also just go to Cloudformation from the AWS Console, and delete the stack if you forget the name. – user3888307 Jul 03 '18 at 20:33
  • 3
    want to add that "sam deploy" is useless. Its a wrapper around "aws cloudformation deploy" that does the same thing and actually has _less_ feature. Sam deploy doesn't have a region switch – red888 Jul 12 '18 at 19:04
  • want to add the sam itself is pretty useless and a bad copy of sls :/ . Sorry for that – Hendrik Jander May 13 '19 at 17:56
  • 1
    `sam deploy` not `sam invoke` and it _was_ useless back when it was just a very wonky wrapper around cloudformation commands (2 years ago). this is no longer the case as the current sam build/package/deploy workflow solved most problems but you still have to use a different command (cloudformation) to cleanup/destroy a sam app which is a slight inconvenience – red888 Jun 16 '20 at 13:52
  • 1
    Now there is a `sam delete` command. [Doc](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-delete.html) – jesusnoseq Jun 20 '22 at 10:48