serverless / serverless-python-requirements

⚡️🐍📦 Serverless plugin to bundle Python packages
MIT License
1.11k stars 291 forks source link

Lambda function is packaged and uploaded every time, when no changes have been made #834

Open mrchops1024 opened 8 months ago

mrchops1024 commented 8 months ago

Are you certain it's a bug?

Are you using the latest plugin release?

Is there an existing issue for this?

Issue description

Despite no changes being made to my python Lambda function, it is packaged and uploaded to S3 on every deploy. Here is what the directory structure for this basic project looks like:

./serverless.yml
./.gitignore
./package-lock.json
./package.json
./lambda
./lambda/requirements.txt
./lambda/index.py

Service configuration (serverless.yml) content

service: serverless-python-requirements-test

frameworkVersion: '3'

plugins:
  - serverless-python-requirements

package:
  individually: true

custom:
  pythonRequirements:
    slim: true
    noDeploy:
      - boto3
      - botocore
      - jmespath
      - python-dateutil
      - s3transfer
      - six
      - urllib3

provider:
  name: aws
  region: us-west-2
  runtime: python3.11
  stackName: cfn-stack-usw2-serverless-python-requirements-test
  deploymentBucket:
    name: s3-usw2-serverless-python-requirements-test
    maxPreviousDeploymentArtifacts: 5
  deploymentPrefix: 'functions'
  versionFunctions: false

functions:
  serverless-python-requirements-test:
    name: lambda-usw2-serverless-python-requirements-test
    role: lambdaRole
    handler: index.lambda_handler
    module: lambda
    package:
      patterns:
        - '!**/.venv/**'
        - '!**/__pycache__/**'
        - '!**/__init__.py'

resources:
  Resources:
    lambdaRole:
      Type: AWS::IAM::Role
      Properties:
        Path: /
        RoleName: iam-role-serverless-python-requirements-test
        AssumeRolePolicyDocument:
          Version: '2012-10-17'
          Statement:
            - Effect: Allow
              Action: sts:AssumeRole
              Principal:
                Service:
                  - lambda.amazonaws.com
        Policies:
          - PolicyName: iam-policy-serverless-python-requirements-test
            PolicyDocument:
              Version: '2012-10-17'
              Statement:
                - Effect: Allow
                  Action:
                    - 'logs:CreateLogGroup'
                    - 'logs:CreateLogStream'
                    - 'logs:PutLogEvents'
                    - 's3:ListAllMyBuckets'
                  Resource: '*'

Command name and used flags

serverless deploy --verbose

Command output

Deploying serverless-python-requirements-test to stage dev (us-west-2)

Packaging
Generated requirements from /Users/user/Projects/serverless-python-requirements-test/lambda/requirements.txt in /Users/user/Projects/serverless-python-requirements-test/.serverless/lambda/requirements.txt
Using static cache of requirements found at /Users/user/Library/Caches/serverless-python-requirements/01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b_x86_64_slspyc
Excluding development dependencies for function "serverless-python-requirements-test"
Injecting required Python packages to package
Retrieving CloudFormation stack
Uploading
Uploading CloudFormation file to S3
Uploading State file to S3
Uploading service lambda-lambda-usw2-serverless-python-requirements-test.zip file to S3 (537 B)
Updating CloudFormation stack
Creating new change set
Waiting for new change set to be created
Change Set did not reach desired state, retrying
Executing created change set
  UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - cfn-stack-usw2-serverless-python-requirements-test
  UPDATE_IN_PROGRESS - AWS::Lambda::Function - ServerlessDashpythonDashrequirementsDashtestLambdaFunction
  UPDATE_COMPLETE - AWS::Lambda::Function - ServerlessDashpythonDashrequirementsDashtestLambdaFunction
  UPDATE_COMPLETE_CLEANUP_IN_PROGRESS - AWS::CloudFormation::Stack - cfn-stack-usw2-serverless-python-requirements-test
  UPDATE_COMPLETE - AWS::CloudFormation::Stack - cfn-stack-usw2-serverless-python-requirements-test
Retrieving CloudFormation stack
Removing old service artifacts from S3

✔ Service deployed to stack cfn-stack-usw2-serverless-python-requirements-test (29s)

functions:
  serverless-python-requirements-test: lambda-usw2-serverless-python-requirements-test (537 B)

Stack Outputs:
  ServerlessDeploymentBucketName: s3-usw2-serverless-python-requirements-test

Need a faster logging experience than CloudWatch? Try our Dev Mode in Console: run "serverless dev"

Environment information

Framework Core: 3.38.0 (local)
Plugin: 7.2.3
SDK: 4.5.1
pgrzesik commented 7 months ago

Hey @mrchops1024 👋 Sorry you've run into trouble. I tried reproducing it on a simpler case and I wasn't able to do so. Would you be able to check what is the difference in final zip between the deploys?

mrchops1024 commented 7 months ago

I just ran a deploy, which uploaded the .zip to S3 and ran a Cloudformation update. I copied the .zip file out of the .serverless directory and ran deploy again, with the same results.

Comparing the two .zip files and they look identical based on contents:

./requirements.txt
./index.py
./.completed_requirements