Reputation: 23
I did as much research as I could but I can`t seem to find a way to structure my folder the way I want to.
My folder structure looks like this:
aws-lambdas
database_credentials.yml (just a file to read the creds from in a var)
serverless.yml
functions
ETLTool
somefile1.py
somefile2.py
lambda_function.py
ETLToolFullLoadSLS.yml
ETLToolSLS.yml
TriggerSnowflakeETL
somefile1.py
somefile2.py
lambda_function.py
TriggerSnowflakeETLSLS.yml
What I want to do is to pull in all the .yml from inside the functions folder into the serverless.yml at the root folder. My main serverless.yml file looks as such:
service: SnowflakePoc
frameworkVersion: '2'
custom:
database_credentials: ${file(./database_credentials.yml):database_credentials}
provider:
name: aws
runtime: python3.8
lambdaHashingVersion: 20201221
timeout: 90
memorySize: 2048
stage: dev
region: eu-west-2
vpc:
securityGroupIds:
- sg-013059b0cbf4054b5
- sg-02c6fcaa9f2bfac7f
subnetIds:
- subnet-04aa5cacdb8d9d077
- subnet-0ea7eb629fbc6f6a8
iam:
role: arn:aws:iam::309161096106:role/LamdaRDSAccess
functions:
- ${file(./functions/ETLTool/ETLToolSLS.yml)}
- ${file(./functions/ETLTool/ETLToolFullLoadSLS.yml)}
- ${file(./functions/TriggerSnowflakeETL/TriggerSnowflakeETLSLS.yml)}
plugins:
- serverless-python-requirements
The issue is that the whole functions/* folder is picked up by each of the lambdas even if I have something like this in each inner function yml file.
TriggerETLTool:
timeout: 600
memorySize: 5000
reservedConcurrency: 3
handler: functions/TriggerSnowflakeETL/lambda_function.lambda_handler
layers:
- arn:aws:lambda:eu-west-2:309161096106:layer:Snowflake:3
- arn:aws:lambda:eu-west-2:309161096106:layer:DatabaseUtilities:5
package:
patterns:
- '!functions/TriggerSnowflakeETL/**'
- functions/TriggerSnowflakeETL/lambda_function.py
Inside AWS it looks like this: Pic from AWS Lambda Source Code
Is there a better pattern than having 1 directory per lambda?
I would like just the files inside each function to be at the root of my lambdas without them being inside a folder once they reach AWS as they are in the image. Also I`d like to have just the files from each inner-function inside the functions folder rather than the whole functions directory.
Upvotes: 2
Views: 794
Reputation: 3787
If you want to package each function individually, you'll need two things (one of which you've already done)
serverless.yml
file to package functions individually: service: SnowflakePoc
package:
individually: true
provider:
...
Packaging individually is configurable globally or at a per-function level, so you can choose what's best for you.
You can find more information in the documentation
Upvotes: 1