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: aws-sam-cli version 1.80 unable to sync serverless application #5034

Closed
cnguyenrettig opened this issue Apr 18, 2023 · 11 comments
Closed
Labels
area/sync sam sync command stage/bug-repro The issue/bug needs to be reproduced type/bug

Comments

@cnguyenrettig
Copy link

cnguyenrettig commented Apr 18, 2023

Description:

The newest versions of aws-sam-cli are unable to use the sync serverless application with the AWS toolkit.
This was true over versiosn 1.78, 1.79, and 1.80

AWS Toolkit version is: 1.65-223
aws-cli version: tried both:

  1. aws-cli/2.8.5 Python/3.9.11 Darwin/22.3.0 exe/x86_64 prompt/off
  2. aws-cli/2.11.13 Python/3.11.3 Darwin/22.3.0 exe/x86_64 prompt/off

Steps to reproduce:

Observed result:

Template haven't been changed since last deployment, skipping infra sync...
Queuing up code sync for the resources that require an update
Syncing Lambda Function RetrieveExpenseFunction...
Syncing Lambda Function DeleteExpenseFunction...
Syncing Lambda Function RetrieveExpensesByEmailFunction...
Syncing Lambda Function CreateExpenseListFunction...
Syncing Lambda Function RemoveExpenseItemFromListFunction...
Syncing Lambda Function RetrieveExpenseListsByEmailFunction...
Syncing Lambda Function CreateExpenseFunction...
Syncing Lambda Function AddExpenseItemToListFunction...
Syncing Lambda Function UpdateExpenseFunction...

Error: expected str, bytes or os.PathLike object, not NoneType
Traceback:
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/lib/telemetry/metric.py", line 184, in wrapped
    raise exception  # pylint: disable=raising-bad-type
    ^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/lib/telemetry/metric.py", line 149, in wrapped
    return_value = func(*args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/lib/telemetry/event.py", line 322, in wrapped
    raise exception
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/lib/telemetry/event.py", line 314, in wrapped
    return_value = func(*args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/lib/cli_validation/image_repository_validation.py", line 92, in wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/lib/telemetry/metric.py", line 103, in wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/lib/utils/version_checker.py", line 42, in wrapped
    actual_result = func(*args, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/cli/main.py", line 92, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/commands/_utils/cdk_support_decorators.py", line 39, in wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/commands/_utils/command_exception_handler.py", line 93, in wrapper_command_exception_handler
    raise ex
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/commands/_utils/command_exception_handler.py", line 73, in wrapper_command_exception_handler
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/commands/sync/command.py", line 212, in cli
    do_cli(
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/commands/sync/command.py", line 411, in do_cli
    execute_code_sync(
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/commands/sync/command.py", line 496, in execute_code_sync
    executor.execute()
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/lib/sync/sync_flow_executor.py", line 192, in execute
    self._execute_step(executor, exception_handler)
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/lib/sync/sync_flow_executor.py", line 243, in _execute_step
    if self._handle_result(sync_flow_future, exception_handler):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/lib/sync/sync_flow_executor.py", line 303, in _handle_result
    exception_handler(exception)
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/lib/sync/sync_flow_executor.py", line 104, in default_exception_handler
    raise exception
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/lib/sync/sync_flow_executor.py", line 338, in _sync_flow_execute_wrapper
    dependent_sync_flows = sync_flow.execute()
                           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/lib/sync/sync_flow.py", line 383, in execute
    self.gather_resources()
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/lib/sync/flows/zip_function_sync_flow.py", line 96, in gather_resources
    self._zip_file = make_zip_with_lambda_permissions(zip_file_path, self._artifact_folder)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/aws-sam-cli/1.80.0/libexec/lib/python3.11/site-packages/samcli/lib/package/utils.py", line 258, in make_zip_with_permissions
    source_root = os.path.abspath(source_root)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen posixpath>", line 399, in abspath

Expected result:

Sync Serverless Application to load local changes to functional code to AWS

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

  1. OS: macOS: 13.2.1 Ventura

  2. sam --version:
    SAM CLI, version 1.80.0

  3. AWS region:
    us-east-1

# Paste the output of `sam --info` here

(base) Chis-MBP:ata-unit-three-project-cnguyenrettig chinguyen-rettig$ sam --info
{
"version": "1.80.0",
"system": {
"python": "3.11.3",
"os": "macOS-13.2.1-x86_64-i386-64bit"
},
"additional_dependencies": {
"docker_engine": "20.10.21",
"aws_cdk": "Not available",
"terraform": "Not available"
}
}

Add --debug flag to command you are running

@cnguyenrettig cnguyenrettig added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Apr 18, 2023
@lucashuy
Copy link
Contributor

Thanks for opening this issue! I'll try to reproduce this on my side, thanks for providing the versions of SAM CLI you tried.

@lucashuy lucashuy added stage/bug-repro The issue/bug needs to be reproduced area/sync sam sync command labels Apr 19, 2023
@lucashuy
Copy link
Contributor

lucashuy commented Apr 19, 2023

Thanks for waiting, I'm not able to reproduce your behaviour where the SAM sync feature in the AWS Toolkit is unable to sync your project.

I noticed that in your logs, SAM CLI is installed with homebrew with Python 3.11 references, can you try installing SAM CLI through our tap? This can be done by uninstalling the core version and installing the AWS specific version:

brew uninstall aws-sam-cli
brew install aws/tap/aws-sam-cli

You can double check the tap and package name in our installation docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html

@lucashuy lucashuy removed the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Apr 19, 2023
@cnguyenrettig
Copy link
Author

cnguyenrettig commented Apr 21, 2023 via email

@lucashuy
Copy link
Contributor

Hi, unfortunately I do not see the image you've attached in the reply. Is there a minimal project that you can provide where we can reproduce this behaviour (or just a template file and steps to reproduce)?

@cnguyenrettig
Copy link
Author

cnguyenrettig commented Apr 21, 2023 via email

@lucashuy
Copy link
Contributor

Looks like Github scrubs images and attachments from email replies, I don't see anything attached on your original reply

@mndeveci
Copy link
Contributor

@cnguyenrettig would you be able to provide a simple template that we can use to re-produce this issue?

It seems like CodeUri property of the function is invalid, ant sam sync process fails during creating a ZIP file before starting the sync operation. Are you using InlineCode property or pre-built artifacts in ZIP format?

@mndeveci mndeveci added the blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. label May 13, 2023
@cnguyenrettig
Copy link
Author

cnguyenrettig commented May 15, 2023

Pasted template.yml here. I believe it is depending on Application.zip:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Parameters:
  ProjectName:
    Type: String
Resources:
  ProjectStorage:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Join
        - ''
        - - !Ref ProjectName
          - '-datastore'
  createdepartment:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: build/distributions/Application.zip
      Handler: com.kenzie.unit.two.iam.lambda.CreateDepartment
      Runtime: java11
      Description: create department
      MemorySize: 512
      Timeout: 60
      # Function's execution role
      Policies:
        - AWSLambdaBasicExecutionRole
        - AWSLambda_ReadOnlyAccess
        - AWSXrayWriteOnlyAccess
        - AWSLambdaVPCAccessExecutionRole
        - AmazonS3FullAccess
      Tracing: Active
      Environment:
        Variables:
          BucketName:
            Ref: ProjectStorage
  createuser:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: build/distributions/Application.zip
      Handler: com.kenzie.unit.two.iam.lambda.CreateUser
      Runtime: java11
      Description: create user
      MemorySize: 512
      Timeout: 60
      # Function's execution role
      Policies:
        - AWSLambdaBasicExecutionRole
        - AWSLambda_ReadOnlyAccess
        - AWSXrayWriteOnlyAccess
        - AWSLambdaVPCAccessExecutionRole
        - AmazonS3FullAccess
      Tracing: Active
      Environment:
        Variables:
          BucketName:
            Ref: ProjectStorage
  createrole:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: build/distributions/Application.zip
      Handler: com.kenzie.unit.two.iam.lambda.CreateRole
      Runtime: java11
      Description: create role
      MemorySize: 512
      Timeout: 60
      # Function's execution role
      Policies:
        - AWSLambdaBasicExecutionRole
        - AWSLambda_ReadOnlyAccess
        - AWSXrayWriteOnlyAccess
        - AWSLambdaVPCAccessExecutionRole
        - AmazonS3FullAccess
      Tracing: Active
      Environment:
        Variables:
          BucketName:
            Ref: ProjectStorage
  getdepartments:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: build/distributions/Application.zip
      Handler: com.kenzie.unit.two.iam.lambda.GetDepartments
      Runtime: java11
      Description: get departments
      MemorySize: 512
      Timeout: 60
      # Function's execution role
      Policies:
        - AWSLambdaBasicExecutionRole
        - AWSLambda_ReadOnlyAccess
        - AWSXrayWriteOnlyAccess
        - AWSLambdaVPCAccessExecutionRole
        - AmazonS3FullAccess
      Tracing: Active
      Environment:
        Variables:
          BucketName:
            Ref: ProjectStorage
  getusers:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: build/distributions/Application.zip
      Handler: com.kenzie.unit.two.iam.lambda.GetUsers
      Runtime: java11
      Description: get users
      MemorySize: 512
      Timeout: 60
      # Function's execution role
      Policies:
        - AWSLambdaBasicExecutionRole
        - AWSLambda_ReadOnlyAccess
        - AWSXrayWriteOnlyAccess
        - AWSLambdaVPCAccessExecutionRole
        - AmazonS3FullAccess
      Tracing: Active
      Environment:
        Variables:
          BucketName:
            Ref: ProjectStorage
  getroles:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: build/distributions/Application.zip
      Handler: com.kenzie.unit.two.iam.lambda.GetRoles
      Runtime: java11
      Description: get roles
      MemorySize: 512
      Timeout: 60
      # Function's execution role
      Policies:
        - AWSLambdaBasicExecutionRole
        - AWSLambda_ReadOnlyAccess
        - AWSXrayWriteOnlyAccess
        - AWSLambdaVPCAccessExecutionRole
        - AmazonS3FullAccess
      Tracing: Active
      Environment:
        Variables:
          BucketName:
            Ref: ProjectStorage
  assignusertorole:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: build/distributions/Application.zip
      Handler: com.kenzie.unit.two.iam.lambda.AssignUserToRole
      Runtime: java11
      Description: create user role
      MemorySize: 512
      Timeout: 60
      # Function's execution role
      Policies:
        - AWSLambdaBasicExecutionRole
        - AWSLambda_ReadOnlyAccess
        - AWSXrayWriteOnlyAccess
        - AWSLambdaVPCAccessExecutionRole
        - AmazonS3FullAccess
      Tracing: Active
      Environment:
        Variables:
          BucketName:
            Ref: ProjectStorage
  getuserroles:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: build/distributions/Application.zip
      Handler: com.kenzie.unit.two.iam.lambda.GetUserRoles
      Runtime: java11
      Description: get user roles
      MemorySize: 512
      Timeout: 60
      # Function's execution role
      Policies:
        - AWSLambdaBasicExecutionRole
        - AWSLambda_ReadOnlyAccess
        - AWSXrayWriteOnlyAccess
        - AWSLambdaVPCAccessExecutionRole
        - AmazonS3FullAccess
      Tracing: Active
      Environment:
        Variables:
          BucketName:
            Ref: ProjectStorage
  canwarehouseuserpackitem:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: build/distributions/Application.zip
      Handler: com.kenzie.unit.two.warehouse.lambda.CanUserPackItem
      Runtime: java11
      Description: can warehouse user pack item
      MemorySize: 512
      Timeout: 60
      # Function's execution role
      Policies:
        - AWSLambdaBasicExecutionRole
        - AWSLambda_ReadOnlyAccess
        - AWSXrayWriteOnlyAccess
        - AWSLambdaVPCAccessExecutionRole
        - AmazonS3FullAccess
      Tracing: Active
      Environment:
        Variables:
          BucketName:
            Ref: ProjectStorage
  viewemployeepaycheck:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: build/distributions/Application.zip
      Handler: com.kenzie.unit.two.employee.lambda.ViewEmployeePayCheck
      Runtime: java11
      Description: can user view employee paycheck
      MemorySize: 512
      Timeout: 60
      # Function's execution role
      Policies:
        - AWSLambdaBasicExecutionRole
        - AWSLambda_ReadOnlyAccess
        - AWSXrayWriteOnlyAccess
        - AWSLambdaVPCAccessExecutionRole
        - AmazonS3FullAccess
      Tracing: Active
      Environment:
        Variables:
          BucketName:
            Ref: ProjectStorage
  caninvoiceclient:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: build/distributions/Application.zip
      Handler: com.kenzie.unit.two.warehouse.lambda.CanInvoiceClient
      Runtime: java11
      Description: can warehouse user pack item
      MemorySize: 512
      Timeout: 60
      # Function's execution role
      Policies:
        - AWSLambdaBasicExecutionRole
        - AWSLambda_ReadOnlyAccess
        - AWSXrayWriteOnlyAccess
        - AWSLambdaVPCAccessExecutionRole
        - AmazonS3FullAccess
      Tracing: Active
      Environment:
        Variables:
          BucketName:
            Ref: ProjectStorage

@moelasmar moelasmar added stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. and removed blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. labels May 23, 2023
@mndeveci mndeveci added type/bug and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels May 24, 2023
@mndeveci
Copy link
Contributor

Thanks for providing the template.

For your regular deployment workflow, I assume you are not running sam build but your are running sam deploy directly with the template above?

@mildaniel
Copy link
Contributor

Closing as this bug has now been fixed and released in version 1.86.0 of the CLI. Should anything new arise, please open a new issue.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 8, 2023

⚠️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/sync sam sync command stage/bug-repro The issue/bug needs to be reproduced type/bug
Projects
None yet
Development

No branches or pull requests

5 participants