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

Suddenly getting traceback: AttributeError: 'NoneType' object has no attribute 'items' #6014

Closed
garretwilson opened this issue Sep 29, 2023 · 13 comments
Labels
blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.

Comments

@garretwilson
Copy link

I'm on Windows 10. A day or two ago I updated to SAM CLI, version 1.97.0. I don't know for sure if it's related to the upgrade, but now deploying a very simple template gives me:

Traceback (most recent call last):
  File "runpy.py", line 194, in _run_module_as_main
  File "runpy.py", line 87, in _run_code
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\__main__.py", line 12, in <module>
    cli(prog_name="sam")
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1686, in invoke
    sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 943, in make_context
    self.parse_args(ctx, args)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1408, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 2400, in handle_parse_result
    value = self.process_value(ctx, value)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 2362, in process_value
    value = self.callback(ctx, self, value)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\_utils\options.py", line 170, in artifact_callback
    for _template_artifact in get_template_artifacts_format(template_file=template_file)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\_utils\template.py", line 301, in get_template_artifacts_format
    for _, resource in template_dict.get("Resources", {}).items():
AttributeError: 'NoneType' object has no attribute 'items'

Why?!

@garretwilson garretwilson added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Sep 29, 2023
@GavinZZ
Copy link
Contributor

GavinZZ commented Sep 29, 2023

Hi there, would you mind sharing that simple template so that I can investigate?

@garretwilson
Copy link
Author

I stress that this was not happening before. I've never seen this before. And the template is dirt simple:

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

Description:
  Foo service.

Parameters:
  Env:
    Description: The token identifying the deployment environment, such as "dev", "dev3", or "dev-jdoe".
    Type: String
    AllowedPattern: '\w[\w-]*'
    ConstraintDescription: The development environment identifier must only use word characters and dashes.

Globals:
  Function:
    Runtime: java17
    Architectures: [x86_64]
    MemorySize: 800
    Timeout: 4 aws/serverless-application-model#4 s

Resources:
  LambdaHandler:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub "foo-${Env}-LambdaHandler"
      CodeUri: !Sub "s3://foo-${Env}-staging/foo-aws-lambda.zip"
      Handler: com.example.LambdaHandler::handleRequest

This is being invoked from Git Bash using the following command:

        sam deploy \
            --profile $awsProfile \
            --template-file "$samTemplateFile" \
            --stack-name $stackName \
            --s3-bucket $stagingBucketName \
            --capabilities CAPABILITY_NAMED_IAM \
            --parameter-overrides Env=$env

Note that there is no SAM config file. I shouldn't need one—everything is being passed on the command line. Furthermore, as I mentioned, it worked fine before.

@GavinZZ
Copy link
Contributor

GavinZZ commented Sep 29, 2023

Unfortunately I'm unable to reproduce the issue you described. Here is my full log. I used the same template you provided, except updating the CodeUri to point to my own s3 bucket URI.

Here is the template I used:

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

Description:
  Foo service.

Parameters:
  Env:
    Description: The token identifying the deployment environment, such as "dev", "dev3", or "dev-jdoe".
    Type: String
    AllowedPattern: '\w[\w-]*'
    ConstraintDescription: The development environment identifier must only use word characters and dashes.

Globals:
  Function:
    Runtime: java17
    Architectures: [x86_64]
    MemorySize: 800
    Timeout: 4 aws/serverless-application-model#4 s

Resources:
  LambdaHandler:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub "foo-${Env}-LambdaHandler"
      CodeUri: !Sub s3://deployment-bucket-${Env}-name-123/helloworld.app.zip # I changed this to point to my own bucket
      Handler: com.example.LambdaHandler::handleRequest

Here is the log of my deployment process:

➜  SAMPlayGround sam --version      
SAM CLI, version 1.97.0 # note that I am also on latest version


➜  SAMPlayGround sam build    
The resource AWS::Serverless::Function 'LambdaHandler' has specified S3 location for CodeUri. It will not be built and SAM CLI does not support invoking it locally.                                                  

Build Succeeded

Built Artifacts  : .aws-sam/build
Built Template   : .aws-sam/build/template.yaml

Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke
[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
[*] Deploy: sam deploy --guided
➜  SAMPlayGround sam deploy --guided

Configuring SAM deploy
======================

        Looking for config file [samconfig.toml] :  Found
        Reading default arguments  :  Success

        Setting default arguments for 'sam deploy'
        =========================================
        Stack Name [reprofailedtemplatewithcodeuri]: reprofailedcustomertemplate
        AWS Region [us-west-2]: 
        Parameter Env [random]: 
        #Shows you resources changes to be deployed and require a 'Y' to initiate deploy
        Confirm changes before deploy [y/N]: 
        #SAM needs permission to be able to create roles to connect to the resources in your template
        Allow SAM CLI IAM role creation [Y/n]: 
        #Preserves the state of previously provisioned resources when an operation fails
        Disable rollback [y/N]: 
The resource AWS::Serverless::Function 'LambdaHandler' has specified S3 location for CodeUri. It will not be built and SAM CLI does not support invoking it locally.                                                  
        Save arguments to configuration file [Y/n]: 
        SAM configuration file [samconfig.toml]: 
        SAM configuration environment [default]: 

        Looking for resources needed for deployment:

        Managed S3 bucket: aws-sam-cli-managed-default-samclisourcebucket-6wfg4pcf3im2
        A different default S3 bucket can be set in samconfig.toml and auto resolution of buckets turned off by setting resolve_s3=False

        Saved arguments to config file
        Running 'sam deploy' for future deployments will use the parameters saved above.
        The above parameters can be changed by modifying samconfig.toml
        Learn more about samconfig.toml syntax at 
        https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html


        Deploying with following values
        ===============================
        Stack name                   : reprofailedcustomertemplate
        Region                       : us-west-2
        Confirm changeset            : False
        Disable rollback             : False
        Deployment s3 bucket         : aws-sam-cli-managed-default-samclisourcebucket-6wfg4pcf3im2
        Capabilities                 : ["CAPABILITY_IAM"]
        Parameter overrides          : {"Env": "random"}
        Signing Profiles             : {}

Initiating deployment
=====================

        Uploading to reprofailedcustomertemplate/06b0a337a8379afbe58db2ced40be68b.template  866 / 866  (100.00%)


Waiting for changeset to be created..

CloudFormation stack changeset
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Operation                                            LogicalResourceId                                    ResourceType                                         Replacement                                        
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Add                                                LambdaHandlerRole                                    AWS::IAM::Role                                       N/A                                                
+ Add                                                LambdaHandler                                        AWS::Lambda::Function                                N/A                                                
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Changeset created successfully. arn:aws:cloudformation:us-west-2:649563674902:changeSet/samcli-deploy1696017816/12d780de-3384-47df-8559-6dbb907343d8


2023-09-29 13:03:47 - Waiting for stack create/update to complete

CloudFormation events from stack operations (refresh every 5.0 seconds)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ResourceStatus                                       ResourceType                                         LogicalResourceId                                    ResourceStatusReason                               
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE_IN_PROGRESS                                   AWS::CloudFormation::Stack                           reprofailedcustomertemplate                          User Initiated                                     
CREATE_IN_PROGRESS                                   AWS::IAM::Role                                       LambdaHandlerRole                                    -                                                  
CREATE_IN_PROGRESS                                   AWS::IAM::Role                                       LambdaHandlerRole                                    Resource creation Initiated                        
CREATE_COMPLETE                                      AWS::IAM::Role                                       LambdaHandlerRole                                    -                                                  
CREATE_IN_PROGRESS                                   AWS::Lambda::Function                                LambdaHandler                                        -                                                  
CREATE_IN_PROGRESS                                   AWS::Lambda::Function                                LambdaHandler                                        Resource creation Initiated                        
CREATE_COMPLETE                                      AWS::Lambda::Function                                LambdaHandler                                        -                                                  
CREATE_COMPLETE                                      AWS::CloudFormation::Stack                           reprofailedcustomertemplate                          -                                                  
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Successfully created/updated stack - reprofailedcustomertemplate in us-west-2

@GavinZZ
Copy link
Contributor

GavinZZ commented Sep 29, 2023

Have you run sam build after you changed the template?

@garretwilson
Copy link
Author

Have you run sam build after you changed the template?

I don't use sam build; that is irrelevant here. I am only using the command I mentioned.

From your output it seems that you are not running the exact command I provided; thus we don't know if you can reproduce the issue or not.

@garretwilson
Copy link
Author

If you decide to run the exact command I'm running, don't forget to delete the samconfig.toml that was generated above when you used some other command.

@garretwilson
Copy link
Author

Maybe this ticket is better moved to https://github.com/aws/aws-sam-cli/ ?

@GavinZZ
Copy link
Contributor

GavinZZ commented Sep 29, 2023

Yes, I confirmed that the template has no transform issue. Will move to SAM CLI instead.

@GavinZZ GavinZZ transferred this issue from aws/serverless-application-model Sep 29, 2023
@garretwilson
Copy link
Author

After a reboot the error is no longer occurring. I also remember that the error started occurring after I used a VPN and then turned off the VPN.

Is it possible that Python could be caching some sort of network configuration from the VPN? I don't have time to test the VPN again at the moment, but I wanted to leave this extra detail.

@sriram-mv
Copy link
Contributor

I tried to reproduce this @garretwilson but could not. It's strange that it was transient and its no longer manifesting when turning off the VPN. It should not have any bearing on this. 🤔

@sriram-mv sriram-mv added blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Oct 5, 2023
@garretwilson
Copy link
Author

garretwilson commented Oct 5, 2023

It's strange that it was transient and its no longer manifesting when turning off the VPN.

It is strange, but to clarify, when this happened I had just turned off the VPN and it happened with the VPN off. I was thinking Python had cached some network routing or DNS entry or something while the VPN was on, and was still trying to access that with the VPN off. Just a wild guess.

Today I tried the same VPN connection, and used SAM both with the VPN on and after turning off the VPN connection. The problem did not occur.

Thus at the moment I cannot reproduce it either.

@hnnasit
Copy link
Contributor

hnnasit commented Dec 15, 2023

Closing this issue as it seems like a transient issue which cannot be reproduced. Feel free to open a new issue if you still face similar issues with the latest SAM CLI version or have steps to reproduce it.

@hnnasit hnnasit closed this as completed Dec 15, 2023
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
blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.
Projects
None yet
Development

No branches or pull requests

4 participants