Comments (5)
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.
@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.
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.
I am closing this issue due to inactivity. Please open a new issue if you still have questions.
from aws-sam-cli.
⚠️ 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)
- `BuildMethod: esbuild` does not include bundled files HOT 2
- Bug: AWS::Events::Rule EventBusName -> 'name' member must satisfy regular expression pattern [\.\-_A-Za-z0-9]+ HOT 4
- Api Gateway requests with query string always response 400 HOT 3
- Bug: python 3.12 with setuptools installed and distutils still being required. HOT 5
- VStudio Debug for Typescript Lambda function gives Runtime.ImportModuleError HOT 7
- Feature request: Support for Python requirements files with different names HOT 3
- Bug: "sam build - TypeError" When building Docker Image from documentation HOT 1
- SamCli standard template with no modifications fails validation HOT 6
- Feature request: switch to add SO_REUSEPORT to main socket in local start-lambda / start-api HOT 1
- JSON decode error HOT 4
- Lambda response must be valid json HOT 3
- Feature request: Support publishing SAM template to SAR that leverages an existing macro HOT 2
- Getting `ValueError: Function name is required` when running API Gateway from Terraform HOT 4
- Bug: sam local start-api - ResponseParserError HOT 2
- `'str' object has no attribute 'decode'` when `PortAlreadyInUse` error is raised. HOT 2
- Feature request: Enhance generate-event to support chained events in common patterns. HOT 3
- Version 1.120.0 Affected by CVE-2024-5535 HOT 1
- Bug: sam deploy - KeyError HOT 2
- Feature request: Upgrade cfn-lint dependency HOT 2
- Add Rust support to aws cli --use-container builds HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-sam-cli.