Giter Club home page Giter Club logo

Comments (5)

hnnasit avatar hnnasit commented on August 16, 2024

Hi @Mason-Stahl, thanks for reporting the issue. Can you try changing the CodeUri value to DiscordBots/recommendations/src and check if this works.

Resources:
  RefreshSpotifyTokens:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: DiscordBots/recommendations/src/

This is assuming the Lambda handler is defined in DiscordBots\recommendations\src\file.py.

RequirementsFile does not seem like a valid value in Metadata to me. The Metadata field is useful when you want to run a custom build of your own. More details can be found here. Let me know if that makes sense or have questions.

from aws-sam-cli.

Mason-Stahl avatar Mason-Stahl commented on August 16, 2024

@hnnasit Thank you so much! That fixed it!

I'm new to this kind of stuff and wondering what the best practice would be if file.py has some imports in other parts of the code like in DiscordBots/my_package? Now that URI points specifically to recommendations/src it seems like I have two options to get the higher level my_package files into recommendations/src, i can use symlink or a custom build script. Is there another better option?

My end goal, I believe, is for DiscordBots folder to be in an ec2 instance, with lambda scheduling the execution of certain commands/files within the recommendations folder.

if it helps at all one of the imports is get_connection_pool() with my_package/src/db/async_db.py having a function to initiate a connection pool that is checked when accessing the database for any necessary DiscordBots command

from aws-sam-cli.

hnnasit avatar hnnasit commented on August 16, 2024

The options you mentioned would work. Another option is to use CodeUri: DiscordBots/, move the requirements.txt to the root folder and specify the handler Handler: recommendations/src/app.lambda_handler. Take a look at the example below:

.
├── DiscordBots
│   ├── __init__.py
│   ├── my_package
│   │   ├── __init__.py
│   │   └── src
│   │       └── db
│   │           ├── __init__.py
│   │           └── async_db.py
│   ├── recommendations
│   │   ├── __init__.py
│   │   └── src
│   │       ├── __init__.py
│   │       └── app.py
│   └── requirements.txt
├── README.md
├── __init__.py
├── samconfig.toml
└── template.yaml

app.py

import json
from my_package.src.db.async_db import get_connection_pool

def lambda_handler(event, context):
    """
    """
    get_connection_pool()
    return {
        "statusCode": 200,
        "body": json.dumps({
            "message": "hello world",
        }),
    }

async_db.py

def get_connection_pool():
    print("DB connection")

template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  sam-app-6962

  Sample SAM Template for sam-app-6962

# 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:
      CodeUri: DiscordBots/
      Handler: recommendations/src/app.lambda_handler
      Runtime: python3.8
      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

If you want to have multiple lambda functions with shared files, you could also checkout Lambda layers. Let me know if that helps or if you have more questions.

from aws-sam-cli.

hnnasit avatar hnnasit commented on August 16, 2024

I am closing this issue due to inactivity. Please open a new issue if you still have questions.

from aws-sam-cli.

github-actions avatar github-actions commented on August 16, 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.