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

Bug: sam build - TypeError #6787

Closed
yan-olydis opened this issue Mar 6, 2024 · 5 comments
Closed

Bug: sam build - TypeError #6787

yan-olydis opened this issue Mar 6, 2024 · 5 comments
Labels
area/build sam build command blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days

Comments

@yan-olydis
Copy link

Description:

when i run my github action i have an error unhashable type: 'list'

my sam info
Run sam --info
{
"version": "1.110.0",
"system": {
"python": "3.11.3",
"os": "Linux-6.5.0-1015-azure-x86_64-with-glibc2.35"
},
"additional_dependencies": {
"docker_engine": "24.0.9",
"aws_cdk": "Not available",
"terraform": "1.7.4"
},
"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"
]
}

Steps to reproduce:

run sam build in my github action
name: Main Workflow

on:
push:
branches:
- main # Change this to the branch you want to trigger on

jobs:
deploy:
runs-on: ubuntu-latest

steps:
  - name: Checkout repository
    uses: actions/checkout@v4

  - name: Run Checkov action
    id: checkov
    uses: bridgecrewio/checkov-action@v12
    with:
      directory: '.'
      framework: cloudformation
      soft_fail: true # optional: do not return an error code if there are failed checks

  - name: Set up AWS CLI
    uses: aws-actions/configure-aws-credentials@v4
    with:
      aws-access-key-id: ${{ secrets.AWS_PUSHER_ACCESS_KEY }}
      aws-secret-access-key: ${{ secrets.AWS_PUSHER_SECRET_KEY }}
      aws-region: eu-west-3

  - name: Display contents of build folder
    run: ls -l

  - name: Build CloudFormation Stack
    run: |
      sam --info 
      sam build \
        --template-file main.yml \
        --use-container \
        --parallel

  - name: Deploy CloudFormation Stack
    run: |
      sam deploy \
          --s3-bucket plating-bucket-infra-01 \
          --stack-name main \
          --template-file .aws-sam/build/template.yaml \
          --parameter-overrides EnvType=development \
          --capabilities CAPABILITY_AUTO_EXPAND

Observed result:

Starting Build inside a container

Error: unhashable type: 'list'
Traceback:
File "click/core.py", line 1078, in main
File "click/core.py", line 1688, in invoke
File "click/core.py", line 1434, in invoke
File "click/core.py", line 783, in invoke
File "samcli/cli/cli_config_file.py", line 347, in wrapper
File "click/decorators.py", line 92, in new_func
File "click/core.py", line 783, in invoke
File "samcli/lib/telemetry/metric.py", line 185, in wrapped
File "samcli/lib/telemetry/metric.py", line 150, in wrapped
File "samcli/lib/utils/version_checker.py", line 43, in wrapped
File "samcli/cli/main.py", line 95, in wrapper
File "samcli/commands/build/command.py", line 174, in cli
File "samcli/commands/build/command.py", line 239, in do_cli
File "samcli/commands/build/build_context.py", line 185, in enter
File "samcli/commands/build/build_context.py", line 191, in set_up
File "samcli/lib/providers/sam_stack_provider.py", line 281, in get_stacks
File "samcli/lib/providers/sam_stack_provider.py", line 270, in get_stacks
File "samcli/lib/providers/sam_stack_provider.py", line 62, in init
File "samcli/lib/providers/sam_base_provider.py", line 200, in get_template
File "samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 253, in resolve_template
File "samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py", line 277, in resolve_attribute

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-%20TypeError
Or create a bug report:
https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20build%20-%20TypeError
Error: Process completed with exit code 1.

Expected result:

deploy my cloudformation template

@yan-olydis yan-olydis added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Mar 6, 2024
@hnnasit
Copy link
Contributor

hnnasit commented Mar 6, 2024

Hi @yan-olydis, thanks for reporting the issue. Could you share your template file? SAM CLI does not cover resolving all the intrinsic functions and from the traceback, this might be throwing an error because of that.

@hnnasit hnnasit added blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. area/build sam build command and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Mar 6, 2024
@yan-olydis
Copy link
Author

this is my template
AWSTemplateFormatVersion: '2010-09-09'

Parameters:

General parameters

EnvType:
Description: Environment Type
Type: String
AllowedValues:
- development
- staging
- production

DBInstanceClass:
Description: Instance class
Type: String

isEnableDeletionProtection:
Description: Enable Deletion Protection
Type: String
Default: false
AllowedValues:
- true
- false

isEnableBackup:
Description: Enable DocumentDB Backup
Type: String
Default: false
AllowedValues:
- true
- false

Conditions:
isProduction: !Equals [ !Ref EnvType, "production" ]
isDev: !Equals [ !Ref EnvType, "development" ]

Mappings:
Network:
development:
NbAzs: 3
CidrBlockPrefix: 10.1
CidrBlock: 10.1.0.0/16
staging:
NbAzs: 3
CidrBlockPrefix: 10.2
CidrBlock: 10.2.0.0/16
production:
NbAzs: 3
CidrBlockPrefix: 10.3
CidrBlock: 10.3.0.0/16

Resources:
Network:
Type: AWS::CloudFormation::Stack
Properties:
StackName: my-vpc
TemplateURL: 'network/vpc.yml'
Parameters:
EnvType: !Ref EnvType
RegionAzs: !FindInMap [Network, !Ref EnvType, NbAzs]
CidrBlockPrefix: !FindInMap [Network, !Ref EnvType, CidrBlockPrefix]

EcsCluster:
Type: AWS::CloudFormation::Stack
Properties:
StackName: my-ecs
TemplateURL: 'ecs/ecs.yml'
Parameters:
EnvType: !Ref EnvType
VpcId: !GetAtt Network.Outputs.VpcId
CidrBlockPrefix: !FindInMap [Network, !Ref EnvType, CidrBlockPrefix]

LoadBalancing:
Type: AWS::CloudFormation::Stack
Properties:
StackName: my-nlb
TemplateURL: 'nlb/nlb.yml'
Parameters:
VpcId: !GetAtt Network.Outputs.VpcId
PrivateSubnets: !GetAtt Network.Outputs.PrivateSubnets
PrivateHostedZoneId: !GetAtt Network.Outputs.PrivateHostedZoneId

DocumentDB:
Type: AWS::CloudFormation::Stack
DependsOn:
- Encryption
Properties:
StackName: my-database
TemplateURL: 'db/db.yml'
Parameters:
EnvType: !Ref EnvType
PrivateSubnets: !GetAtt Network.Outputs.PrivateSubnets
AvailabilityZones: !GetAtt Network.Outputs.AvailabilityZones
EncryptionKeyId: !GetAtt Encryption.Outputs.EncryptionKeyId
DBInstanceClass: !Ref DBInstanceClass
isEnableDeletionProtection: !Ref isEnableDeletionProtection
isEnableBackup: !Ref isEnableBackup
VpcId: !GetAtt Network.Outputs.VpcId

Encryption:
Type: AWS::CloudFormation::Stack
Properties:
StackName: my-encryption-key
TemplateURL: encryption/encryption.yml
Parameters:
EnvType: !Ref EnvType

@hnnasit
Copy link
Contributor

hnnasit commented Mar 10, 2024

Thanks for providing the template file. I tried running sam build on the below template, but the command succeeds for me. I don't see any lambda/serverless functions in the template you provided as well. Would you be able to provide the nested stack templates? My guess is there is some intrinsic function in that template which SAM CLI does not support.

template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  sam-app-6787

  Sample SAM Template for sam-app-6787

Parameters:     
  EnvType:
    Description: Environment Type
    Type: String
    AllowedValues:
      - development
      - staging
      - production

  DBInstanceClass:
    Description: Instance class
    Type: String

  isEnableDeletionProtection:
    Description: Enable Deletion Protection
    Type: String
    Default: false
    AllowedValues:
      - true
      - false

  isEnableBackup:
    Description: Enable DocumentDB Backup
    Type: String
    Default: false
    AllowedValues:
      - true
      - false

  Conditions:
    isProduction: !Equals [ !Ref EnvType, "production" ]
    isDev: !Equals [ !Ref EnvType, "development" ]

  Mappings:
    Network:
      development:
        NbAzs: 3
        CidrBlockPrefix: 10.1
        CidrBlock: 10.1.0.0/16
      staging:
        NbAzs: 3
        CidrBlockPrefix: 10.2
        CidrBlock: 10.2.0.0/16
      production:
        NbAzs: 3
        CidrBlockPrefix: 10.3
        CidrBlock: 10.3.0.0/16

Resources:
  Network:
    Type: AWS::CloudFormation::Stack
    Properties:
      StackName: my-vpc
      TemplateURL: 'nested-template.yaml'
    Parameters:
      EnvType: !Ref EnvType
      RegionAzs: !FindInMap [Network, !Ref EnvType, NbAzs]
      CidrBlockPrefix: !FindInMap [Network, !Ref EnvType, CidrBlockPrefix]

  EcsCluster:
    Type: AWS::CloudFormation::Stack
    Properties:
      StackName: my-ecs
      TemplateURL: 'nested-template.yaml'
    Parameters:
      EnvType: !Ref EnvType
      VpcId: !GetAtt Network.Outputs.VpcId
      CidrBlockPrefix: !FindInMap [Network, !Ref EnvType, CidrBlockPrefix]

  LoadBalancing:
    Type: AWS::CloudFormation::Stack
    Properties:
      StackName: my-nlb
      TemplateURL: 'nested-template.yaml'
    Parameters:
      VpcId: !GetAtt Network.Outputs.VpcId
      PrivateSubnets: !GetAtt Network.Outputs.PrivateSubnets
      PrivateHostedZoneId: !GetAtt Network.Outputs.PrivateHostedZoneId

  DocumentDB:
    Type: AWS::CloudFormation::Stack
    DependsOn:
      - Encryption
    Properties:
      StackName: my-database
      TemplateURL: 'nested-template.yaml'
    Parameters:
      EnvType: !Ref EnvType
      PrivateSubnets: !GetAtt Network.Outputs.PrivateSubnets
      AvailabilityZones: !GetAtt Network.Outputs.AvailabilityZones
      EncryptionKeyId: !GetAtt Encryption.Outputs.EncryptionKeyId
      DBInstanceClass: !Ref DBInstanceClass
      isEnableDeletionProtection: !Ref isEnableDeletionProtection
      isEnableBackup: !Ref isEnableBackup
      VpcId: !GetAtt Network.Outputs.VpcId

  Encryption:
    Type: AWS::CloudFormation::Stack
    Properties:
      StackName: my-encryption-key
      TemplateURL: 'nested-template.yaml'
    Parameters:
      EnvType: !Ref EnvType

@hnnasit hnnasit added blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days and removed blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. labels Apr 16, 2024
@mildaniel
Copy link
Contributor

Closing due to inactivity.

Copy link
Contributor

⚠️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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build sam build command blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days
Projects
None yet
Development

No branches or pull requests

3 participants