Coder Social home page Coder Social logo

serverless-plugin-aws-resource-names's Introduction

serverless-plugin-aws-resource-names

serverless

Serverless plugin to enable custom AWS resource names

Usage

Install the plugin to your project:

npm install serverless-aws-resource-names --save

Add the plugin and its configuration to your serverless project:

plugins:
  - serverless-aws-resource-names
custom:
  serverless-aws-resource-names:
    source: mapping.json

Create the mapping.json file in your project and modify the names to your hearts desire!

{
    "template": {
        "compiled": "cloudformation-template-update-stack.json",
        "core": "cloudformation-template-create-stack.json"
    },
    "stack": "$service-$stage",
    "role": {
        "Fn::Join": [
            "-", [
                "$service",
                "$stage",
                "$region",
                "lambdaRole"
            ]
        ]
    },
    "policy": {
        "Fn::Join": [
            "-", [
                "$stage",
                "$service",
                "lambda"
            ]
        ]
    },
    "apiGateway": "$stage-$service",
    "lambda": "$service-$stage-$lambda",
    "logGroup": "/aws/lambda/$service-$stage-$lambda"
}

Mapping Variable Reference

  • $service - Refers to the service attribute in your serverless.yml
  • $stage - Refers to the stage which you deploy to via serverless e.g. sls deploy -s dev
  • $region - Refers to the AWS region that you are deploying to. This is configured in your serverless.yml under the provider.region attribute or by your AWS CLI configuration.
  • $lambda - Refers to the name of your lambda function, defined in your serverless.yml under the functions attribute.
  • $rand - Globally replaces all instances with a random UUID.

Custom Variables

You can define custom variables in your serverless.yml file:

plugins:
  - serverless-aws-resource-names
custom:
  serverless-aws-resource-names:
    source: mapping.json
    variables:
      functionSuffix: func

And then use these custom variables in your mapping.json file:

{
    "lambda": "$service-$stage-$lambda-$functionSuffix",
}

Here we've defined a custom variable functionSuffix and assigned it the value 'func'.

This will append the string 'func' to all of your Lambda function names.

serverless-plugin-aws-resource-names's People

Contributors

concon121 avatar ericballetbaz avatar mprzytulski avatar mtwtfss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

serverless-plugin-aws-resource-names's Issues

Using custom IAM role causes TypeError: Cannot read property 'Properties' of undefined

When using a custom IAM role in serverless.yml it causes a "TypeError: Cannot read property 'Properties' of undefined"

Sample conf:

provider:
  name: aws
  region: eu-west-1
  role: arn:aws:iam::0123456789:role/roleInMyAccount

Full error stack

 TypeError: Cannot read property 'Properties' of undefined
     at AWSNaming.fixLogGroups (C:\xxx\node_modules\serverless-aws-resource-names\naming.js:78:33)
     at C:\Users\eballet-baz\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:498:55
     at tryCatcher (C:\Users\eballet-baz\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\util.js:16:23)
     at Object.gotValue (C:\Users\eballet-baz\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\reduce.js:168:18)
     at Object.gotAccum (C:\Users\eballet-baz\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\reduce.js:155:25)
     at Object.tryCatcher (C:\Users\eballet-baz\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\util.js:16:23)
     at Promise._settlePromiseFromHandler (C:\Users\eballet-baz\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:547:31)
     at Promise._settlePromise (C:\Users\eballet-baz\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:604:18)
     at Promise._settlePromise0 (C:\Users\eballet-baz\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:649:10)
     at Promise._settlePromises (C:\Users\eballet-baz\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:729:18)
     at _drainQueueStep (C:\Users\eballet-baz\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\async.js:93:12)
     at _drainQueue (C:\Users\eballet-baz\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\async.js:86:9)
     at Async._drainQueues (C:\Users\eballet-baz\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\async.js:102:5)
     at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\eballet-baz\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\async.js:15:14)

statement.Resource.filter is not a function

Hi, I am tring to deploy a serverless application, which uses serverless-aws-resource-names but I am getting:

`(base) PS>serverless deploy --stage dev
Serverless: Setting custom naming conventions...
Serverless: Setting custom function names...
Serverless: Generated requirements from D:...\requirements.txt in D:....serverless\requirements.txt...
Serverless: Installing requirements from D:....serverless\requirements\requirements.txt ...
Serverless: Running ...
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Injecting required Python packages to package...

Type Error ---------------------------------------------

statement.Resource.filter is not a function

 For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com

Your Environment Information ---------------------------
OS: win32
Node Version: 8.9.3
Serverless Version: 1.44.1`

The only place where statement.Resource.filter is present is here:

node_modules\serverless-aws-resource-names\naming.js

And I can not figure it out why and how to overcome this.
Any info would be great.

Many thanks,

Cannot read properties of undefined (reading 'compiled')

Using a simple config:

plugins:
  - serverless-aws-resource-names

custom:
  serverless-aws-resource-names:
    source: mapping.json

with mapping.json:

{
    "stack": "$service"
}

Receiving this error message:

Running "serverless" from node_modules
Setting custom naming conventions...
Setting custom function names...

Deploying simple to stage dev (us-east-1)

โœ– Stack simple failed to deploy (0s)
Environment: darwin, node 20.4.0, framework 3.38.0 (local) 3.38.0v (global), plugin 7.2.0, SDK 4.5.1
Credentials: Local, "nonprod-ilm" profile
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
TypeError: Cannot read properties of undefined (reading 'compiled')
    at Object.getCompiledTemplateFileName (/Users/salem/Work/Oddity/repos/serverless-templates/node_modules/serverless-aws-resource-names/naming.js:30:44)
    at AwsPackage.saveCompiledTemplate (/Users/salem/Work/Oddity/repos/serverless-templates/node_modules/serverless/lib/plugins/aws/package/lib/save-compiled-template.js:8:59)
    at aws:package:finalize:saveServiceState (/Users/salem/Work/Oddity/repos/serverless-templates/node_modules/serverless/lib/plugins/aws/package/index.js:118:20)
    at PluginManager.runHooks (/Users/salem/Work/Oddity/repos/serverless-templates/node_modules/serverless/lib/classes/plugin-manager.js:530:15)
    at PluginManager.invoke (/Users/salem/Work/Oddity/repos/serverless-templates/node_modules/serverless/lib/classes/plugin-manager.js:564:20)
    at async PluginManager.spawn (/Users/salem/Work/Oddity/repos/serverless-templates/node_modules/serverless/lib/classes/plugin-manager.js:585:5)
    at async PluginManager.runHooks (/Users/salem/Work/Oddity/repos/serverless-templates/node_modules/serverless/lib/classes/plugin-manager.js:530:9)
    at async PluginManager.invoke (/Users/salem/Work/Oddity/repos/serverless-templates/node_modules/serverless/lib/classes/plugin-manager.js:564:9)
    at async PluginManager.spawn (/Users/salem/Work/Oddity/repos/serverless-templates/node_modules/serverless/lib/classes/plugin-manager.js:585:5)
    at async before:deploy:deploy (/Users/salem/Work/Oddity/repos/serverless-templates/node_modules/serverless/lib/plugins/deploy.js:48:11)
    at async PluginManager.runHooks (/Users/salem/Work/Oddity/repos/serverless-templates/node_modules/serverless/lib/classes/plugin-manager.js:530:9)
    at async PluginManager.invoke (/Users/salem/Work/Oddity/repos/serverless-templates/node_modules/serverless/lib/classes/plugin-manager.js:563:9)
    at async PluginManager.run (/Users/salem/Work/Oddity/repos/serverless-templates/node_modules/serverless/lib/classes/plugin-manager.js:604:7)
    at async Serverless.run (/Users/salem/Work/Oddity/repos/serverless-templates/node_modules/serverless/lib/serverless.js:179:5)
    at async /Users/salem/Work/Oddity/repos/serverless-templates/node_modules/serverless/scripts/serverless.js:819:9

handle functions referenced by ${file(location)}

i have my functions broken into folders and the parent service references the function serverless from each folder.

this plugin doesn't handle this

services.yaml
functions:

  • ${file(./auth-service/serverless.yml)}

TypeError: Cannot create property 'events' on string '${file(./auth-service/serverless.yml)}'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.