jorgebastida / gordon

λ Gordon is a tool to create, wire and deploy AWS Lambdas using CloudFormation
Other
2.05k stars 137 forks source link

Share build settings between lambdas? #152

Closed dotkas closed 6 years ago

dotkas commented 6 years ago

Is it possible to enable the sharing of build settings, using parameters?

After looking around in the code, it seems that gordon requires the build parameter values to be iterable, even if it is a reference to a parameter:

settings.yml for a lambda:

lambdas:
  auth:
    code: auth
    handler: code.handler
    runtime: python
    build: ref://Builds

parameters/common.yml:

Builds:
    - cp -Rf * {target}
    - cp -Rf {project_path}/config {target}
    - cp -Rf {project_path}/utils {target}
    - pip install -r {project_path}/requirements.txt -q -t {target}
    - cd {target} && find . -name "*.pyc" -delete

Error:

(env)ec2-user@ip-172-30-0-225:~/git/minyan-backend$ gordon build
Loading project resources
Loading installed applications
  contrib_lambdas:
    ✓ lambdas:version
  user:
    ✓ lambdas:auth
Building project...
  0001_p.json
Traceback (most recent call last):
  File "/home/ec2-user/git/minyan-backend/env/bin/gordon", line 9, in <module>
    load_entry_point('gordon==0.5.0', 'console_scripts', 'gordon')()
  File "/home/ec2-user/git/minyan-backend/env/local/lib/python2.7/site-packages/gordon/bin.py", line 109, in main
    getattr(obj, options.func)()
  File "/home/ec2-user/git/minyan-backend/env/local/lib/python2.7/site-packages/gordon/core.py", line 243, in build
    self._build_pre_resources_template()
  File "/home/ec2-user/git/minyan-backend/env/local/lib/python2.7/site-packages/gordon/core.py", line 318, in _build_pre_resources_template
    r.register_pre_resources_template(template)
  File "/home/ec2-user/git/minyan-backend/env/local/lib/python2.7/site-packages/gordon/resources/lambdas.py", line 357, in register_pre_resources_template
    f.write(self.get_zip_file().read())
  File "/home/ec2-user/git/minyan-backend/env/local/lib/python2.7/site-packages/gordon/resources/lambdas.py", line 463, in get_zip_file
    self._collect_lambda_content(destination)
  File "/home/ec2-user/git/minyan-backend/env/local/lib/python2.7/site-packages/gordon/resources/lambdas.py", line 501, in _collect_lambda_content
    self._collect_lambda_module_content(destination, **kwargs)
  File "/home/ec2-user/git/minyan-backend/env/local/lib/python2.7/site-packages/gordon/resources/lambdas.py", line 514, in _collect_lambda_module_content
    command = command.format(
AttributeError: 'Ref' object has no attribute 'format'

All my lambdas in this given project require custom build settings due to dependability on a utils library, and a configuration library, as seen. So it would be tedious to apply exactly the same build settings to every single lambda entry.