aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.52k stars 1.17k forks source link

sam delete fails due to nested stack templateURL #3513

Open sdesousa86 opened 2 years ago

sdesousa86 commented 2 years ago

Description:

Hello, I noticed an issue regarding nested stack declaration when used in an AWS SAM template file. On deletion, the version_checker.py raises the following error: URL given to the parse method is not a valid S3. It seems that the version_checker.py is complaining because the TemplateURL is not starting with "s3://".

SAM CLI version used: 1.36.0 (also tested with v1.33.0)

Steps to reproduce:

  1. Add a nested stack declaration to your AWS SAM template YAML file, with an hard-coded string for the TemplateURL parameter

    MyNestedStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://my-nested-stack-bucket.s3.eu-west-1.amazonaws.com/my-nested-stack-cfn-template.yaml
  2. Build and deploy your SAM application

  3. Try to delete your previously deployed Cloudformation stack with the sam delete command line

Observed result:

Traceback (most recent call last):
  File "samcli/__main__.py", line 12, in <module>
  File "click/core.py", line 829, in __call__
  File "click/core.py", line 782, in main
  File "click/core.py", line 1259, in invoke
  File "click/core.py", line 1066, in invoke
  File "click/core.py", line 610, in invoke
  File "click/decorators.py", line 73, in new_func
  File "click/core.py", line 610, in invoke
  File "samcli/lib/utils/version_checker.py", line 42, in wrapped
  File "samcli/cli/main.py", line 90, in wrapper
  File "samcli/commands/delete/command.py", line 83, in cli
  File "samcli/commands/delete/command.py", line 101, in do_cli
  File "samcli/commands/delete/delete_context.py", line 349, in run
  File "samcli/commands/delete/delete_context.py", line 300, in delete
  File "samcli/lib/package/artifact_exporter.py", line 265, in delete
  File "samcli/lib/package/packageable_resources.py", line 169, in delete
  File "samcli/lib/package/packageable_resources.py", line 186, in get_property_value
  File "samcli/lib/package/s3_uploader.py", line 265, in parse_s3_url
  ValueError: URL given to the parse method is not a valid S3 url https://my-nested-stack-bucket.s3.eu-west-1.amazonaws.com/my-nested-stack-cfn-template.yaml**
  [76] Failed to execute script __main__

Expected result:

The TemplateURL parameter value of a AWS::CloudFormation::Stack resource is ignored by the version_checker.py and "sam delete" command is successful.

Current workaround:

For an unknown reason, just adding !Sub in front of the TemplateURL's value (even if you don't use it to compute the TemplateURL's value) seems to resolve the issue:

MyNestedStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: !Sub https://my-nested-stack-bucket.s3.eu-west-1.amazonaws.com/my-nested-stack-cfn-template.yaml
xazhao commented 2 years ago

Hey thanks for posting this issue. It looks like a bug to me. We only allow path-style s3 bucket access here. It can be fixed if we support virtual-hosted-style s3 bucket access. I have created an internal task to keep track of this.