saltstack / saltstack/salt

[BUG] Updating labmda using boto_lambda.function_present is broken

Open
#58,857 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

boto bug severity-medium
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description

boto_lambda.function_present can create a lambda function successfully however running the same state to update even if there is no change gives the following error :

     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python3.6/site-packages/salt/state.py", line 2154, in call
                  *cdata["args"], **cdata["kwargs"]
                File "/usr/lib/python3.6/site-packages/salt/loader.py", line 2188, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/states/boto_lambda.py", line 354, in function_present
                  profile,
                File "/usr/lib/python3.6/site-packages/salt/states/boto_lambda.py", line 520, in _function_code_present
                  hashed = sha.digest().encode("base64").strip()
              AttributeError: 'bytes' object has no attribute 'encode'

Setup

create_function:
  boto_lambda.function_present:
    - name: myfunction
    - FunctionName: myfunction_name2
    - Runtime: python3.6
    - Role: labmda_role
    - Handler: main
    - ZipFile: /srv/salt/lambda/code/code.zip
    - profile: myprofile

Steps to Reproduce the behavior
Try to create a simple lambda function using boto_lambda.function_present and run the state again. It always fails if the lambda exists. If you manually remove the lambda and run the state it works. it only fails when tries to update

Expected behavior
When I edit the line 520 in /usr/lib/python3.6/site-packages/salt/states/boto_lambda.py and remove encode("base64") salt state works fine both for create and update

        Original : #hashed = sha.digest().encode("base64").strip()
        Changed to : hashed = sha.digest().strip()

Screenshots

Versions Report

salt-minion-3002-1.el7.noarch
salt-master-3002-1.el7.noarch

# salt --versions-report
Salt Version:
           Salt: 3002

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.8.1
      docker-py: 2.6.1
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 2.11.1
        libgit2: Not Installed
       M2Crypto: 0.35.2
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: Not Installed
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 3.6.8 (default, Apr  2 2020, 13:34:55)
   python-gnupg: Not Installed
         PyYAML: 3.13
          PyZMQ: 17.0.0
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.1.4

System Versions:
           dist: centos 7 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-1127.19.1.el7.x86_64
         system: Linux
        version: CentOS Linux 7 Core

Additional context
Add any other context about the problem here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in salt/states/boto_lambda.py at line 520 and reproduce the issue by running boto_lambda.function_present twice with the provided state. Verify that an existing function can be checked or updated without the bytes encoding error, while preserving successful creation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
cloud, devops
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.