![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@conio/serverless-plugin-ifelse
Advanced tools
A Serverless Plugin to write If Else conditions in serverless YAML file
While you can use serverless variables to define different values for your atrributes based on either stage or other properties, it sometimes is not as straightforward.
For example, If you have a serverless project with 3 functions and you want to deploy all 3 functions in one region but only 2 of them in other region, then there is no easier way to exlude the third function based on region you are deploying.
Another use case that inspired me to write this plugin was, I wanted to use iamRoleStatements
for all my Lambda functions in staging but use a pre-define role
in production. You cannot have both attributes in serverless.yml file as serverless ignores iamRoleStatements
if there is role
attribute.
This plugin allows you to write if else conditions in serverless.yml
file to add, remove or change the values of attributes in the yml file. It works with both package
and deploy
commands. It also works with serverless-offline
plugin.
npm i serverless-plugin-ifelse --save-dev
serverless.yml
service: serverlessIfElseExample
custom:
currentStage: ${opt:stage, self:provider.stage}
serverlessIfElse:
- If: '"${self:custom.currentStage}" == "dev"'
Exclude:
- provider.role
- provider.environment.ENV1
- functions.func3
- functions.func1.events.0.http.authorizer
Set:
provider.timeout: 90
provider.profile: dev
ElseExclude:
- provider.environment.ENV2
ElseSet:
provider.timeout: 120
- ExcludeIf:
functions.func1: '"${self:provider.region}" == "ap-southeast-2"'
functions.func2: '"${opt:region}" == "us-east-1"'
- If: '"${self:provider.region}" == "us-east-1"'
Exclude:
- functions.func1
Set:
provider.timeout: 300
plugins:
- serverless-plugin-ifelse
provider:
name: aws
runtime: nodejs8.10
stage: dev
region : ap-southeast-2
timeout: 60
environment:
ENV1: env-val-1
ENV2: env-val-2
profile: default
iamRoleStatements:
- Effect: Allow
Action:
- s3:*
Resource: "*"
role: arn:aws:iam::xxxxxxxxxxxx:role/testRole
functions:
func1:
name: Function 1
handler: lambda.func1
events:
- http:
path: "path1"
method: "post"
authorizer:
arn: arn:aws:cognito-idp:us-east-1:123456789012:userpool/us-east-1_0acCDefgh
func2:
name: Function 2
handler: lambda.func2
events:
- http:
path: "path2"
method: "post"
func3:
name: Function 3
handler: lambda.func2
events:
- http:
path: "path3"
method: "post"
Put your conditions in custom variable serverlessIfElse
.
Write your if condition inside single quote ''
. Inside your condition, all your variables that resolve in string or the string themselves should be inside double quote. The plugin will otherwise encounter undefined variable error and the condition will not work. The condition can be anything, like == , !=, <, > or even javascript regular expressions.
- If: '"${self:provider.stage}" == "dev"'
If condition in If is true, all attibutes in Exclude will be ignored before serverless package or deploy your stack and hence serverless will not see those attributes.
If condition in If is true, the value of the attribute will be updated with new value.
If condition in If is false,the attibutes will be ignored.
If condition in If is false, the value of the attribute will be updated with new value.
Use ExcludeIf, if you want to write conditions per attribute. If condition is true, only that attribute will be ignored.
You can write as many conditions as you like and exclude or set attributes any level deep in the yml file.
This plugin will ignore or update value of attributes based on your conditions and does not evaluate if it causes any side effect. You are responsbile to make sure ignoring or setting new values will work as you expected and will not cause serverless to throw error.
The plugin will not remove or update any first level attributes in serverless.yml file like service
or provider
or functions
.
FAQs
A Serverless Plugin to write If Else conditions in serverless YAML file
We found that @conio/serverless-plugin-ifelse demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.