GithubHelp home page GithubHelp logo

Comments (3)

hnnasit avatar hnnasit commented on June 27, 2024 1

Hi @devmuch, thanks for opening the issue. The modules folder needs to be copied to the image as well. Here is a simple project that I have created based on the details you provided:
template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  python3.9

  Sample SAM Template for sam-app-6592

# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
  Function:
    Timeout: 3
    MemorySize: 128

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      PackageType: Image
      Architectures:
        - x86_64
      Events:
        HelloWorld:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /hello
            Method: get
    Metadata:
      Dockerfile: ./hello_world/Dockerfile
      DockerContext: .
      DockerTag: python3.9-v1

app.py

from modules.my_module import create_message

def lambda_handler(event, context):
    return {
        "statusCode": 200,
        "body": create_message()
    }

Dockerfile

FROM public.ecr.aws/lambda/python:3.9

COPY ./hello_world/requirements.txt ./
RUN python3.9 -m pip install -r requirements.txt -t .

COPY ./hello_world/app.py ./
ADD ./modules ./modules

# Command can be overwritten by providing a different command in the template directly.
CMD ["app.lambda_handler"]

directory structure

.
├── README.md
├── __init__.py
├── events
│   └── event.json
├── hello_world
│   ├── Dockerfile
│   ├── __init__.py
│   ├── app.py
│   └── requirements.txt
├── modules
│   └── my_module.py
├── samconfig.toml
├── template.yaml

Let us know if you still have questions.

from aws-sam-cli.

devmuch avatar devmuch commented on June 27, 2024

Thanks for this. I naively assumed it copy the folder contents, but RTFM proves me wrong. :-)

from aws-sam-cli.

github-actions avatar github-actions commented on June 27, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

from aws-sam-cli.

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.