One of the biggest challenges that I've faced using serverless is in deploying AWS Lambda functions in a micro-service fashion (Each lambda individually - I've already tried individual packages, Webpack, and so on...).
I'm currently breaking my serverless app into multiple sub-serverless files and I'm trying to reference a main config serverless one. I'd like to inherit entire object trees so I don't have to be retyping them one by one (In addition, if there's a change, I can propagate it throughout all the lambdas).
Here's my current structure:
| serverless.yml
| lambda/
| /planning
| index.ts
| serverless.yml
| /generator
| index.ts
| serverless.yml
| /createStudents
| index.ts
| serverless.yml
Content of the main serverless file (Omitted for brevity):
## https://serverless.com/framework/docs/providers/aws/guide/serverless.yml/
service: backend-appsync
provider:
name: aws
stage: ${opt:stage, 'dev'}
runtime: nodejs10.x
region: us-east-2
## https://serverless.com/framework/docs/providers/aws/guide/iam/
## https://serverless.com/blog/abcs-of-iam-permissions/
iamRoleStatements:
- Effect: Allow
Action:
- "dynamodb:BatchGetItem"
- "dynamodb:BatchWriteItem"
- "dynamodb:ConditionCheckItem"
- "dynamodb:GetItem"
- "dynamodb:DeleteItem"
- "dynamodb:PutItem"
- "dynamodb:Query"
Resource: "arn:aws:dynamodb:us-east-2:747936726382:table/SchonDB"
I'd like to read the entire provider object and insert it into the individual serverless.yml
file.
Example: /lambda/planning/serverless.yml
service: "planning"
provider: ${file(../../serverless.yml):provider}
functions:
planning:
handler: ./index.handler
name: ${self:provider.stage}-planning
description: Handles the Planning of every teacher.
memorySize: 128
I get the following error:
Serverless Error ---------------------------------------
The specified provider "[object Object]" does not exist. Get Support -------------------------------------------- Docs: docs.serverless.com Bugs: github.com/serverless/serverless/issues Issues: forum.serverless.com
Your Environment Information --------------------------- Operating System: win32 Node Version: 12.14.1 Framework Version: 1.61.2 Plugin Version: 3.2.7 SDK Version: 2.2.1 Components Core Version: 1.1.2 Components CLI Version: 1.4.0
I thought I could reference the entire property. Is this possible? What am I doing wrong? Thanks :)
Serverless goes nuts when files are imported from outside the project directory. To solve this problem, you can now use projectDir:
service: "planning"
projectDir: ../..
provider: ${file(../../serverless.yml):provider}
functions:
planning:
handler: ./index.handler
name: ${self:provider.stage}-planning
description: Handles the Planning of every teacher.
memorySize: 128
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With