aws-sam-cli: sam deploy --guided errors with "S3 Bucket does not exist"

Description

Using sam deploy --guided, the process fails with “Error: S3 Bucket does not exist.”

Steps to reproduce

  1. A developer deployed this stack using sam deploy --guided --template-file realtime.yaml.
  2. Output: Deploying with following values =============================== Stack name : askAroundMe-realtime Region : us-east-1 Confirm changeset : False Deployment s3 bucket : aws-sam-cli-managed-default-samclisourcebucket-kll3li4nzc9r Capabilities : [“CAPABILITY_IAM”] Parameter overrides : {}

Initiating deployment

Error: S3 Bucket does not exist.

Provide steps to replicate.

The developer has also renamed the template to template.yaml to avoid the template parameter, with the same result. Then tried after deleting the toml file with the same result.

Observed result

sam deploy –guided Deploying with following values

    Stack name                 : askAroundMe-realtime
    Region                     : us-east-1
    Confirm changeset          : False
    Deployment s3 bucket       : aws-sam-cli-managed-default-samclisourcebucket-kll3li4nzc9r
    Capabilities               : ["CAPABILITY_IAM"]
    Parameter overrides        : {}

Initiating deployment

Error: S3 Bucket does not exist.

Expected result

The sam deployment should create a deployment bucket and complete.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS:
  2. sam --version:

Add --debug flag to command you are running

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (2 by maintainers)

Most upvoted comments

In addition to the bucket, a sam deployment also creates two cloudformation stacks. One for keeping track of SAM CLI resources, and the other to track the app’s resources. Try deleting these as well.

The sam deploy --guided process looks for a CloudFormation stack, rather than the bucket, to decide whether or not to create a new bucket (S3 API doesn’t give us a good way to search by tags, for example, and since S3 bucket names need to be globally unique this is the approach we need to take). If you’re going to delete the S3 bucket, you’ll also need to delete the associated stack.

You can, of course, always provide your own S3 bucket via samconfig.toml or as a parameter to deployments.

Given that this was filed on another developer’s behalf, I think the question would be what the contents of the aws-sam-cli-managed-default template are, and if there is a bucket present there and this error persists, please reopen this issue. Otherwise, delete the stack and re-run.

Okay I see. This is what happened to me:

  • I previously deployed resources using sam
  • I cleaned up my s3 buckets in my account and removed the bucket managed by the cloudformation stack of sam
  • The cloudformation stack still existed. However, the bucket that was in the stack was deleted
  • When using sam deploy --guided it told me it had found the necessary resources for deployment. Meaning, it found the stack
  • However I couldn’t deploy the stack. It gave me an unrelated error message, for example: Unable to upload artifact hello_world/ referenced by CodeUri parameter of HelloWorldFunction resource.
  • I deleted the sam deployment stack that originally contained the bucket
  • I ran sam deploy --guided. This recreated the sam deployment bucket and deploy worked.

Deleting the aws-sam-cli-managed-default stack on cloudformation console fixed this for me

SAM looks up a cloudformation stack with the name aws-sam-cli-managed-default link` first, and then looks for bucket within the output of that stack.

In addition to the bucket, a sam deployment also creates two cloudformation stacks. One for keeping track of SAM CLI resources, and the other to track the app’s resources. Try deleting these as well.

This worked for me. Thanks a lot. Go to CloundFormation Service -> delete aws-sam-cli-managed-default stack

You can, of course, always provide your own S3 bucket via samconfig.toml or as a parameter to deployments.

Can someone expand on this? In my case, runing sam deploy --guided, sam appears to disregard a custom bucket already defined in samconfig.toml.

Also running sam deploy when param s3_bucket is defined in samconfig.toml recreates Error: S3 Bucket does not exist. It doesn’t look too different from this issue

The sam deploy --guided process looks for a CloudFormation stack, rather than the bucket, to decide whether or not to create a new bucket (S3 API doesn’t give us a good way to search by tags, for example, and since S3 bucket names need to be globally unique this is the approach we need to take). If you’re going to delete the S3 bucket, you’ll also need to delete the associated stack.

You can, of course, always provide your own S3 bucket via samconfig.toml or as a parameter to deployments.

Given that this was filed on another developer’s behalf, I think the question would be what the contents of the aws-sam-cli-managed-default template are, and if there is a bucket present there and this error persists, please reopen this issue. Otherwise, delete the stack and re-run.

Were you able to figure this out? This is happening to me because I deleted the S3 bucket that SAM created on AWS when I first ran sam deploy --guided, but now it’s not recreating that bucket. I’m wondering if there is a way to reset SAM, but deleting the .aws-sam and ~/.aws-sam directories did not work.