Giter Site home page Giter Site logo

Comments (2)

homingli avatar homingli commented on July 24, 2024

You can use -e for setting environment variables, as referenced in Docker documentation:
https://docs.docker.com/engine/reference/run/#env-environment-variables

Example:

$ cat lambda_function.py
def lambda_handler(event, context):
    print(context.memory_limit_in_mb)
    return "It works!"

Without env var:

$ docker run --rm -v "$PWD":/var/task lambci/lambda:python3.6
START RequestId: 11038b32-74fc-40fb-9b41-120aa7065dfe Version: $LATEST
1536
END RequestId: 11038b32-74fc-40fb-9b41-120aa7065dfe
REPORT RequestId: 11038b32-74fc-40fb-9b41-120aa7065dfe Duration: 10 ms Billed Duration: 110.00000000000001 ms Memory Size: 1536 MB Max Memory Used: 18 MB
"It works!"

With env var:

$ docker run --rm -v "$PWD":/var/task -e "AWS_LAMBDA_FUNCTION_MEMORY_SIZE=128"   lambci/lambda:python3.6
START RequestId: ef3b26e2-6780-4564-a0b9-15b45b1293a4 Version: $LATEST
128
END RequestId: ef3b26e2-6780-4564-a0b9-15b45b1293a4
REPORT RequestId: ef3b26e2-6780-4564-a0b9-15b45b1293a4 Duration: 20 ms Billed Duration: 120.0 ms Memory Size: 128 MB Max Memory Used: 18 MB
"It works!"

However, I'm not sure what the behavior here is when your function exceeds the memory limit set by the env var.

from docker-lambda.

mhart avatar mhart commented on July 24, 2024

Thanks @homingli – you're absolutely correct. To actually get docker to restrict the memory to try to simulate what would happen, you can use the -m flag with the docker run command: https://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources

from docker-lambda.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.