kryskruk / serverless-import-config-plugin Goto Github PK
View Code? Open in Web Editor NEWSplit your serverless.yaml config file into smaller modules and import them.
License: MIT License
Split your serverless.yaml config file into smaller modules and import them.
License: MIT License
I have two imported files. One only contains resources, prefixed by Resources:
. The other contains functions and resources (with the appropriate prefixes). sls print shows the resources in the root serverless.yml and the function from the imported file, but not the imported resources.
For some reason, the imported file is not compatible with this plugin: https://github.com/colynb/serverless-dotenv-plugin
It does not use environment variables.
The plugin looks promising, I would like to contribute but I'm a bit occupied at the moment. I hope you can check this out. Thanks!
my serverless.environment.yml
provider:
environment:
AWS_PROFILE: papaya
SERVICE: ${self:service}
REGION: ${self:provider.region}
STAGE: ${self:provider.stage}
APPLE_ENDPOINT: ${ssm:/APPLE_ENDPOINT~true}
APPLE_SECRET: ${ssm:/APPLE_SECRET~true}
ADMIN_SECRET: ${ssm:/ADMIN_SECRET~true}
APOLLO_KEY: ${ssm:/APOLLO_KEY~true}
APOLLO_GRAPH_ID: Apple-oir31
APOLLO_GRAPH_VARIANT: ${file(../../env.${opt:stag, 'dev'}.json):APOLLO_GRAPH_VARIANT}
my serverless.yml
service: papaya-berry-id
app: papaya
org: papaya
provider:
name: aws
profile: papaya
runtime: nodejs12.x
stage: ${opt:stage, 'dev'}
region: "ap-southeast-1"
tracing:
lambda: true
package:
individually: true
excludeDevDependencies: true
plugins:
- serverless-bundle
- serverless-offline
- serverless-import-config-plugin
custom:
import:
- ../../serverless.common.yml
- ../../serverless.environment.yml
- ./serverless.own.yml
functions:
- ${file(./functions/graphql/config.yml)}
On runtime, values are:
AWS_PROFILE: 'papaya',
SERVICE: '${self:service}',
REGION: '${self:provider.region}',
STAGE: '${self:provider.stage}',
APPLE_ENDPOINT: '${ssm:/APPLE_ENDPOINT~true}',
APPLE_SECRET: '${ssm:/APPLE_SECRET~true}',
ADMIN_SECRET: '${ssm:/ADMIN_SECRET~true}',
APOLLO_KEY: '${ssm:/APOLLO_KEY~true}',
APOLLO_GRAPH_ID: 'Apple-oir31',
APOLLO_GRAPH_VARIANT: "${file(../../env.${opt:stag, 'dev'}.json):APOLLO_GRAPH_VARIANT}",
Hello.
First of all thanks a lot for this plugin. I discovered a small issue which affects Windows platform.
On Windows platform the generated path to handler:
functions:
myfeature-myaction:
handler: actions/myaction/handler.handler
includes Windows path separator (\
) instead of posix separator (/
). This results in an error on AWS Lambda.
Could you kindly accept my PR with the proposed fix and publish a new version to npm repository?
Hey!
I was testing this plugin and it works great, but I found one use case, that is not supported.
I would like to import common base serverless.yml file in each stack and in some cases, I may want to overwrite some of the imported keys values. Example:
/serverless.yml
provider:
aws: aws
runtime: nodejs10.x
memory: 128
/childStack/serverless.yml
custom:
import: ../serverless.yml
provider:
memory: 256
Is this possible to achieve this using this plugin?
serverless.yml
service: papaya-berry-id
app: papaya
org: papaya
provider:
name: aws
profile: papaya
runtime: nodejs12.x
stage: ${opt:stage, 'dev'}
region: "ap-southeast-1"
tracing:
lambda: true
environment: ${file(../../serverless.environment.yml)}
package:
individually: true
excludeDevDependencies: true
plugins:
- serverless-bundle
- serverless-offline
- serverless-import-config-plugin
custom:
import:
- ../../serverless.common.yml
- ./serverless.own.yml
functions:
- ${file(./functions/graphql/config.yml)}
serverless.own.yml
provider:
environment:
SOME_VAR: SOME_VALUE
serverless.own.yml
AWS_PROFILE: papaya
SERVICE: ${self:service}
REGION: ${self:provider.region}
STAGE: ${self:provider.stage}
APPLE_ENDPOINT: ${ssm:/APPLE_ENDPOINT~true}
APPLE_SECRET: ${ssm:/APPLE_SECRET~true}
ADMIN_SECRET: ${ssm:/ADMIN_SECRET~true}
APOLLO_KEY: ${ssm:/APOLLO_KEY~true}
APOLLO_GRAPH_ID: Apple-oir31
APOLLO_GRAPH_VARIANT: ${file(../../env.${opt:stag, 'dev'}.json):APOLLO_GRAPH_VARIANT}
results: SOME_VAR
does not exists/undefined
i dont know how to use this plugin, here is my use case:
the to be imported config:
# sls.provider.go.yml
provider:
name: aws
runtime: go1.x
region: ${opt:region, 'eu-central-1'}
stage: ${opt:stage, 'int'}
logRetentionInDays: 90
memorySize: 256
lambdaHashingVersion: "20201221"
timeout: 60
vpc:
securityGroupIds: ${self:custom.ENV_CONFIG.SECURITY_GROUP_IDS}
subnetIds: ${self:custom.ENV_CONFIG.PRIVATE_SUBNET_IDS}
stackTags: ${self:provider.tags}
tags:
PROJECT: 'jhps-dx'
STACK: '${self:service}'
REGION: '${self:provider.region}'
STAGE: '${self:provider.stage}'
# serverless.yml
service: my-service-name
package:
individually: true
plugins:
- serverless-import-config-plugin
custom:
ENV_CONFIG: ${file(serverless.${self:provider.stage}.conf.yml)}
import:
- ./sls.provider.go.yml
functions:
# ...
the output is this:
$ serverless deploy --verbose --conceal -s int --region eu-central-1
Environment: darwin, node 17.5.0, framework 3.2.1, plugin 6.0.0, SDK 4.3.1
Docs: docs.serverless.com
Support: forum.serverless.com
Bugs: github.com/serverless/serverless/issues
Error:
Invalid service configuration: "provider.name" property is missing
so how is this plugin supposed to work? reading all the other issues or the docs wasnt helpful et all...
Trying to import a .js file as this
import:
- module: config/dynamic.js
inputs:
var: test
will throw the following error.
Error: Cannot import config/dynamic.js
Cause: Cannot find module 'config/dynamic.js'
The problem seems to be with the import path, the issue seems to be in this check that will not fail
serverless-import-config-plugin/src/index.ts
Line 144 in 6df1d65
Removing the check fixes the problem.
A solution would be to bypass the check if the file has a .js ext or completely removing the check but don't know if that impacts something else, didn't dig too much into the code.
I'm seeing lots of deprecation warnings like below with serverless 2.25.1.
The stack actually works and did not warn with earlier versions
The variables that are warning, are actually defined AFTER the plugin is processed. It seems that the new serverless version is
emitting the warnings before running the import-config plugin.
How can I suppress the warnings?
Serverless: Deprecation warning: Variables resolver reports following resolution errors:
- Cannot resolve variable at "provider.environment.DB_TABLE": Value not found at "self" source,
My serverless.yml looks like this:
plugins:
- serverless-import-config-plugin
custom:
import:
- '../include/base.yml'
provider:
name: aws
environment:
DB_TABLE: ${self:custom.tableName}
Here are my deps:
├── @babel/[email protected]
├── @babel/[email protected]
├── @babel/[email protected]
├── @babel/[email protected]
├── @babel/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
I have this:
forwarderArn: arn:aws:lambda:us-west-2:${self:custom.awsAccountId.${env:CI_COMMIT_BRANCH}}:function:datadog-forwarder
Works totally fine in one file but if I try to move this to another file and import it using this plugin it does not work
Could not perform GetFunction on arn:aws:lambda:us-west-2:${self:custom.awsAccountId.${env:CI_COMMIT_BRANCH}}:function:datadog-forwarder
The variables are no longer resolved
Is there a way to dinamically provide the list of resources to include depending on some other value (eg: provider.region
) ?
I've tried several approaches but none of them worked.
custom:
import:
- resources/resource.${self:provider.region}.yml
cannot find the file. I think is trying to import it before variable value expansion.
Cannot import resources/resource.${self:provider.region}.yml: the given file doesn't exist
custom:
import: ${file(resources/resource.${self:provider.region}.yml):import}
cannot find the file either. I think it is the same reason.
Cannot import ${file(resources/resource.${self:provider.region}.yml):import}: the given module cannot be resolved
Tried:
- ${file(resources/resource.${self:provider.region}.yml):import}/serverless.yml
- ${file(resources/resource.${self:provider.region}.yml):import}/serverless.yaml
- ${file(resources/resource.${self:provider.region}.yml):import}/serverless.js
.js
import (despite having to workaround #10)custom:
import:
- module: resources.js
inputs:
region: ${self:provider.region}
and resources.js
being:
module.exports = ({region}) => {
return {
custom: {
import: [
`resources/resource.${region}.yml`
]
}
}
}
with the same result:
Cause: Cannot import resources/resource.${self:provider.region}.yml: the given file doesn't exist
Does anyone know how to workaround this issue?
Hi there !
Thank you for supporting the plugin it's really great.
Unfortunately currently I have an issue with merging configuration fragments that contain elements in array which are objects. Take the 2 logically identical fragments for merging:
- DomainName:
'Fn::Join':
- ''
- - Ref: componentsBucket
- '.s3.${opt:region,self:provider.region}.amazonaws.com'
- DomainName:
'Fn::Join':
- ''
- - Ref: componentsBucket
- '.s3.${opt:region,self:provider.region}.amazonaws.com'
Due to the fact that uniqueness of the array elements is shallow the {Ref: componentsBucket} element will be added to the merged array which is not what we expect. current code in merge.ts:10 :
if (Array.isArray(target) && Array.isArray(source)) {
// add unique elements of source into target
return target.concat(source.filter(elem => !target.includes(elem)))
}
To make it work not only for string elements you could consider using lodash differenceWith and isEqual functions to perform a deep array elements comparison. proposed solution:
if (Array.isArray(target) && Array.isArray(source)) {
// add unique elements of source into target with deep elements equality comparison
return target.concat(differenceWith(source, target, isEqual));
}
If you agree with the proposed solution, could you kindly accept the PR and publish a new version to npm repository?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.