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.49k stars 1.17k forks source link

Bug: `Fn::ForEach` with transform `AWS::LanguageExtensions` results in error #6903

Closed sansmoraxz closed 5 months ago

sansmoraxz commented 5 months ago

Description:

Fn::ForEach instrinsic does not seem to work with SAM cli.

Steps to reproduce:

Try to build and deploy the following template with sam:

AWSTemplateFormatVersion: '2010-09-09'
Transform:
  - 'AWS::LanguageExtensions'
  - 'AWS::Serverless-2016-10-31'

Parameters:
  QueueNames:
    Description: Queue Names
    Type: List<String>

Resources:
  'Fn::ForEach::Que':
    - QueueName
    - !Ref QueueNames
    - 'Queue${QueueName}':
        Type: 'AWS::SQS::Queue'

Observed result:

Results in error message:

Error: 'list' object has no attribute 'get'

Full traceback for sam validate --lint:

Error: 'list' object has no attribute 'get'
Traceback:
  File "/home/ubuntu/.local/pipx/venvs/aws-sam-cli/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/ubuntu/.local/pipx/venvs/aws-sam-cli/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/ubuntu/.local/pipx/venvs/aws-sam-cli/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ubuntu/.local/pipx/venvs/aws-sam-cli/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/ubuntu/.local/pipx/venvs/aws-sam-cli/lib/python3.10/site-packages/samcli/cli/cli_config_file.py", line 347, in wrapper
    return func(*args, **kwargs)
  File "/home/ubuntu/.local/pipx/venvs/aws-sam-cli/lib/python3.10/site-packages/click/decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/ubuntu/.local/pipx/venvs/aws-sam-cli/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/ubuntu/.local/pipx/venvs/aws-sam-cli/lib/python3.10/site-packages/samcli/lib/telemetry/metric.py", line 185, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "/home/ubuntu/.local/pipx/venvs/aws-sam-cli/lib/python3.10/site-packages/samcli/lib/telemetry/metric.py", line 150, in wrapped
    return_value = func(*args, **kwargs)
  File "/home/ubuntu/.local/pipx/venvs/aws-sam-cli/lib/python3.10/site-packages/samcli/lib/utils/version_checker.py", line 43, in wrapped
    actual_result = func(*args, **kwargs)
  File "/home/ubuntu/.local/pipx/venvs/aws-sam-cli/lib/python3.10/site-packages/samcli/cli/main.py", line 95, in wrapper
    return func(*args, **kwargs)
  File "/home/ubuntu/.local/pipx/venvs/aws-sam-cli/lib/python3.10/site-packages/samcli/commands/_utils/cdk_support_decorators.py", line 35, in wrapped
    if is_cdk_project(template_dict):
  File "/home/ubuntu/.local/pipx/venvs/aws-sam-cli/lib/python3.10/site-packages/samcli/lib/iac/cdk/utils.py", line 25, in is_cdk_project
    _resource_level_metadata_exists(resources),
  File "/home/ubuntu/.local/pipx/venvs/aws-sam-cli/lib/python3.10/site-packages/samcli/lib/iac/cdk/utils.py", line 44, in _resource_level_metadata_exists
    if resource.get("Type", "") == CDK_METADATA_TYPE_VALUE:

An unexpected error was encountered while executing "sam validate".
Search for an existing issue:
https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20validate%20-%20AttributeError
Or create a bug report:
https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20validate%20-%20AttributeError

Expected result:

Successful deployment through sam build && sam deploy.

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

{
  "version": "1.113.0",
  "system": {
    "python": "3.10.12",
    "os": "Linux-6.5.0-1016-aws-x86_64-with-glibc2.35"
  },
  "additional_dependencies": {
    "docker_engine": "26.0.0",
    "aws_cdk": "2.135.0 (build d46c474)",
    "terraform": "Not available"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}

Add --debug flag to command you are running

sansmoraxz commented 5 months ago

Interesting enough doing this through the AWS CloudFormation UI somehow works.

lucashuy commented 5 months ago

This is a known feature gap with the currently supported intrinsics: https://github.com/aws/aws-sam-cli/issues/5647

Unfortunately I do not have a workaround at this moment. Closing this issue in favour of the linked issue.

github-actions[bot] commented 5 months ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.