npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serverless-resource-names

v1.7.1

Published

Automagically name your Cloudformation resources according to their ref identifier

Downloads

3

Readme

Serverless Resource Names Plugin

This plugin generate resources names from your resource's Logical ID in Resources:

Setup

Install via npm or yarn in the root of your Serverless project:

npm install serverless-resource-names --save-dev

or

yarn add serverless-resource-names --dev

Apply plugin

plugins:
  - serverless-resource-names

Why?

Suppose you have one or many resources in your serverless.yml like so:

Resources:
  SomeQueueOne:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: ${self:service.name}-some-queue-one-${self:provider.stage}
      ...

  SomeQueueTwo:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: ${self:service.name}-some-queue-two-${self:provider.stage}
      ...

  UploadBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: ${self:service.name}-upload-bucket-${self:provider.stage}
      ...

Notice how you have to constantly specify names for these services?

Futhermore you're likely to use them in your environment variables as well

provider:
  environment:
    SOME_QUEUE_ONE: ${self:service.name}-some-queue-one-${self:provider.stage}
    SOME_QUEUE_TWO: ${self:service.name}-some-queue-two-${self:provider.stage}
    UPLOAD_BUCKET: ${self:service.name}-upload-bucket-${self:provider.stage}

This becomes very troublesome to manage when your resources grow and you'll constantly need to add these things

What does it do?

To solve this problem this plugin generates the equivalent resources names by looking at the reference's Logical ID in your serverless.yml

So now you can omit the BucketName (or other name properties for other resources)

So the following resource...

UploadBucket:
  Type: AWS::S3::Bucket
  Properties: ...

...will generate the following based on the reference Logical ID: UploadBucket:

UploadBucket:
  Type: AWS::S3::Bucket
  Properties:
    BucketName: service-name-upload-bucket-dev
functions:
  hello:
    environment:
      UPLOAD_BUCKET: service-name-upload-bucket-dev
      ...
    ...

NOTE: Resources with already existing name properties will not be modifiede but will be injected as environment variables with same naming convetions based of the resources Logical ID

Settings

You can change the prefix for your resources using

custom:
  resourceNames:
    prefix: "awesome-prefix"

Default will prefix using your service name in serverless.yml

Referencing generated names

You can also reference the generated in other resources using the ${name:LogicalId} variable as follows:

functions:
  hello:
    handler: handler.hello
    events:
      - s3:
          bucket: ${name:MyBucket}
          existing: true

resources:
  Resources:
    MyBucket:
      Type: AWS::S3::Bucket

SNS Topics

This plugin will simplify referencing SNS topics. To reference a topic trigger for your lambda simply use: ${topic:TopicResourceName} i.e:

functions:
  hello:
    handler: handler.hello
    events:
      - sns: ${topic:MyTopic}

resources:
  Resources:
    MyTopic:
      Type: AWS::SNS::Topic

The plugin will also inject SNS Topic- & SQS Queue ARNs as an environment variables using the same naming conventions suffixed by _ARN or _URL. For the example above that would be: MY_TOPIC_ARN.

For SQS queues the plugin will suffix and return the queue url value rather than the queue name.

Commands

Run serverless env to print all environment variables (generated and custom)

Note: all Intristic Functions are printed as escaped json

Example:

ENVIRONMENT_VALUE_1=1
ENVIRONMENT_VALUE_2=2
SOME_TOPIC_ARN="{\"Fn::Join\":[\":\",[\"arn\",\"aws\",\"sns\",{\"Ref\":\"AWS::Region\"},{\"Ref\":\"AWS::AccountId\"},\"my-prefix-some-topic-dev\"]]}"
SOME_TOPIC="my-prefix-some-topic-dev"