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

[Migrated] Add Docker Container Image Support #922

Closed
jneves opened this issue Feb 20, 2021 · 7 comments
Closed

[Migrated] Add Docker Container Image Support #922

jneves opened this issue Feb 20, 2021 · 7 comments
Labels
auto-closed [Bot] Closed, details in comments no-activity [Bot] Closing soon if no new activity

Comments

@jneves
Copy link
Contributor

jneves commented Feb 20, 2021

Originally from: Miserlou/Zappa#2188 by ian-whitestone

Earlier this month, AWS announced container image support for AWS Lambda. This means you can now package and deploy lambda functions as container images, instead of using zip files. The container image based approach will solve a lot of headaches caused by the zip file approach, particularly with file sizes (container images can be up to 10GB) and the dependency issues we all know & love.

In an ideal end state, you should be able to call zappa deploy / zappa update / zappa package (etc.) and specify whether you want to use the traditional zip-based approach or new Docker container based approach. If choosing the latter, Zappa would automatically:

  • Build the new docker image for you
    • Not 100% sure how this would work yet. There is a Python library for docker that could be used. Would need to detect the dependencies a user has in their virtual env. and then install them all in the Docker image creation flow.
    • A simpler alternative could involve a user having a Dockerfile that they point Zappa to, and Zappa just executes the build for that.
  • Pushes the docker image to Amazon's Container Registry solution
    • Automatically creates new repository if one does not exist
  • Creates the lambda function with the new Docker image

For a MVP, we should take a BYOI (bring your own image) approach and just get zappa deploy and zappa update to deploy a lambda function using an existing Docker Image that complies with these guidelines.

ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Mar 16, 2021
ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Mar 16, 2021
ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Mar 16, 2021
ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Mar 16, 2021
ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Mar 17, 2021
ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Mar 21, 2021
ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Apr 18, 2021
ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Apr 18, 2021
ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Jun 13, 2021
ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Jun 13, 2021
ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Jun 13, 2021
ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Jun 13, 2021
ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Jun 13, 2021
ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Jun 13, 2021
ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Jun 13, 2021
ian-whitestone added a commit to ian-whitestone/Zappa-1 that referenced this issue Jun 13, 2021
@ian-whitestone
Copy link
Contributor

Initially functionality added in #967

@ian-whitestone
Copy link
Contributor

@ian-whitestone using the -d / --docker-image-uri flag, is there a way to pass in multiple --build-arg flags for the image?

@alexanderdamiani when you run zappa deploy prod --docker-image-uri <uri> it is expecting a pre-built docker image. In the current state, you are expected to build your docker image in a separate step, outside of zappa, before deploying it. There's more details on the workflow in this post.

@ian-whitestone
Copy link
Contributor

ian-whitestone commented Jul 23, 2021

Keep in mind that Lambdas which are created from ECR have very long cold starts: for my project it's 4.5 seconds compared with 1.2 seconds before
Looks like we need a feature like "concurrency" for warmups

@ArtikUA yes cold starts are slower with docker images. I'm working on a post now to benchmark this for lambda's used for ML deployments.

Of course you can use the keep_warm setting, but that won't solve for cold starts that occur when requests are spiking and Lambda starts autoscaling.

@programmingwithalex
Copy link

programmingwithalex commented Sep 17, 2021

@ian-whitestone I am able to deploy with no issues using docker containers. However, I am not able to deploy with a docker container via GitHub Actions. The issue is referenced in issue #2131 but the issue pertains to zip files and not containers.

My current GitHub Action for zappa deployment is:

- name: configure aws credentials
  uses: aws-actions/configure-aws-credentials@v1
  with:
    aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
    aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    aws-region: ${{ env.AWS_DEFAULT_REGION }}

- name: Deploy dev
   run: |
     pip install virtualenv
     virtualenv my-deploy
     source my-deploy/bin/activate
     pip install -r requirements.txt zappa
     zappa update dev -d ${{ secrets.AWS_ECR_IMAGE_URI }}:latest
  env:
    AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
    AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    AWS_DEFAULT_REGION: us-east-1

with my traceback:

Traceback (most recent call last):

  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/zappa/cli.py", line 3422, in handle
    sys.exit(cli.handle())
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/zappa/cli.py", line 588, in handle
    self.dispatch_command(self.command, stage)
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/zappa/cli.py", line 619, in dispatch_command
    self.load_settings(self.vargs.get("settings_file"))
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/zappa/cli.py", line 2619, in load_settings
    self.zappa = Zappa(
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/zappa/core.py", line 343, in __init__
==============
    self.load_credentials(boto_session, profile_name)
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/zappa/core.py", line 3565, in load_credentials
    self.boto_session = boto3.Session(
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/boto3/session.py", line 80, in __init__
    self._setup_loader()
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/boto3/session.py", line 120, in _setup_loader
    self._loader = self._session.get_component('data_loader')
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/botocore/session.py", line 698, in get_component
    return self._components.get_component(name)
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/botocore/session.py", line 937, in get_component
    self._components[name] = factory()
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/botocore/session.py", line 158, in <lambda>
    lambda:  create_loader(self.get_config_variable('data_path')))
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/botocore/session.py", line 251, in get_config_variable
    return self.get_component('config_store').get_config_variable(
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/botocore/configprovider.py", line 321, in get_config_variable
    return provider.provide()
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/botocore/configprovider.py", line 418, in provide
    value = provider.provide()
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/botocore/configprovider.py", line 479, in provide
    scoped_config = self._session.get_scoped_config()
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/botocore/session.py", line 351, in get_scoped_config
    raise ProfileNotFound(profile=profile_name)
botocore.exceptions.ProfileNotFound: The config profile (default) could not be found

@ian-whitestone
Copy link
Contributor

ian-whitestone commented Sep 17, 2021

hey @alexanderdamiani ,

did you try doing this: "and removed the profile_name from the zappa_settings.json" mentioned in Miserlou/Zappa#2131 (comment)?

my guess is you have a profile_name specified in the zappa_settings, so it botocore will look for that in you ~/.aws/config. if it's not there, it should fallback to looking in your env variables

henrikhorluck added a commit to dotkom/onlineweb4 that referenced this issue Apr 1, 2022
henrikhorluck added a commit to dotkom/onlineweb4 that referenced this issue Apr 1, 2022
henrikhorluck added a commit to dotkom/onlineweb4 that referenced this issue Apr 1, 2022
Copy link

github-actions bot commented Apr 3, 2024

Hi there! Unfortunately, this Issue has not seen any activity for at least 90 days. If the Issue is still relevant to the latest version of Zappa, please comment within the next 10 days if you wish to keep it open. Otherwise, it will be automatically closed.

@github-actions github-actions bot added the no-activity [Bot] Closing soon if no new activity label Apr 3, 2024
Copy link

Hi there! Unfortunately, this Issue was automatically closed as it had not seen any activity in at least 100 days. If the Issue is still relevant to the latest version of Zappa, please open a new Issue.

@github-actions github-actions bot added the auto-closed [Bot] Closed, details in comments label Apr 13, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-closed [Bot] Closed, details in comments no-activity [Bot] Closing soon if no new activity
Projects
None yet
Development

No branches or pull requests

3 participants