Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use ForEach intrinsic function to define resources #3641

Closed
smasset-veolia opened this issue Aug 20, 2024 · 6 comments
Closed

Can't use ForEach intrinsic function to define resources #3641

smasset-veolia opened this issue Aug 20, 2024 · 6 comments
Labels
area/intrinsics Ref, If, Sub, GetAtt, ... type/feature

Comments

@smasset-veolia
Copy link

Description

The SAM CLI fails to parse templates using the ForEach intrinsic function to define resources. The build first fails in aws-sam-translator code.

Comments in a similar issue reported in the sam-cli project (aws/aws-sam-cli#5647) point to a fix recently merged in AWS CLI (aws/aws-cli#8096). Applying similar changes in both aws-sam-translator (see #3636) and aws-sam-cli on a local test environment fixes the issue.

Steps to reproduce

Run sam build with the example provided in the function reference documentation

Observed result

The command fails in aws-sam-translator code with the following traceback:

Starting Build use cache                                                                                                                   
2024-07-05 08:13:52 Plugin 'ServerlessAppPlugin' raised an exception: 'list' object has no attribute 'get'
Traceback (most recent call last):
  File "samtranslator/plugins/sam_plugins.py", line 130, in act
  File "samtranslator/metrics/method_decorator.py", line 116, in wrapper_cw_timer
  File "samtranslator/plugins/application/serverless_app_plugin.py", line 124, in on_before_transform_template
  File "samtranslator/sdk/template.py", line 34, in iterate
  File "samtranslator/sdk/resource.py", line 26, in __init__
AttributeError: 'list' object has no attribute 'get'

Error: 'list' object has no attribute 'get'
Traceback:
  File "click/core.py", line 1055, in main
  File "click/core.py", line 1657, in invoke
[...]
  File "samcli/lib/samlib/wrapper.py", line 73, in run_plugins
  File "samcli/lib/samlib/wrapper.py", line 130, in parse
  File "samtranslator/plugins/sam_plugins.py", line 136, in act
  File "samtranslator/plugins/sam_plugins.py", line 130, in act
  File "samtranslator/metrics/method_decorator.py", line 116, in wrapper_cw_timer
  File "samtranslator/plugins/application/serverless_app_plugin.py", line 124, in on_before_transform_template
  File "samtranslator/sdk/template.py", line 34, in iterate
  File "samtranslator/sdk/resource.py", line 26, in __init__

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

Expected result

The command shouldn't fail and output:

Build Succeeded

Additional environment details

  1. OS: Debian Bookworm
  2. If using the SAM CLI, sam --version: reproduced with both SAM CLI, version 1.121.0 and SAM CLI, version 1.123.0
  3. AWS region: eu-west-1
@smasset-veolia smasset-veolia added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Aug 20, 2024
@aaythapa
Copy link
Contributor

aaythapa commented Aug 23, 2024

Hi there, thanks for opening this issue and for contributing to SAM. Seems like a valid request to me, I'll try to look through your PR early next week

@aaythapa aaythapa added type/feature area/intrinsics Ref, If, Sub, GetAtt, ... and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Aug 23, 2024
@jfuss
Copy link
Contributor

jfuss commented Aug 26, 2024

We shouldn't be adding support for Fn::ForEach in this repo and instead should be in SAM CLI. We shouldn't fail the way we do here but that doesn't mean we should be re-implementing it in SAM.

Context:
Intrinsics are supported through AWS::LanguageExtensions. This is only available through deployments though and how SAM supports this today.

Instrinsics have caused multiple issues over the year for us and why we now recommend customers to use AWS::LanguageExtensions with SAM now.

The issue here is not that SAM doesn't support Fn::ForEach but that SAM CLI does not support AWS::LanguageExtensions. SAM CLI issue regarding this: aws/aws-sam-cli#5647

@aaythapa
Copy link
Contributor

Agree with Jacob on this, didn't realize that SAM CLI doesn't support Language Extensions and thats what was causing the issue. Closing this issue for now, thanks again for bringing this up. Feel free to re-open if you want to discuss further.

Copy link
Contributor

This issue is now closed. 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.

@brianhhq
Copy link

brianhhq commented Sep 5, 2024

hi @jfuss , as a customer, we would expect it to be working and integrate it well with the feature AWS provide.
if this is not the right place, would you please raise the request in the right place and put a link here?

In addition, if this is right "Instrinsics have caused multiple issues over the year for us", why hasn't it been resolved or in the backlog to resolve.

when I was notified that cloud formation support for loop feature, I was super happy and write article to celebrate it. but I was disappointed that one of my favourite tool - sam does not work well with it.

if this is not going into the right direction, how would we recommend sam over terraform to others/clients

@aaythapa
Copy link
Contributor

aaythapa commented Sep 6, 2024

Hi @brianhhq aws/aws-sam-cli#5647 this feature request to support Language Extensions in SAM CLI would be the right request to use as the issue is with the sam build command rather than the actual transform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/intrinsics Ref, If, Sub, GetAtt, ... type/feature
Projects
None yet
Development

No branches or pull requests

4 participants