Giter Club home page Giter Club logo

serverless-stack-output's Introduction

Serverless Stack Output Plugin

npm license CircleCI Coveralls

A serverless plugin to store output from your AWS CloudFormation Stack in JSON/YAML/TOML files, or to pass the output to a JavaScript function for further processing.

Usage

Install

$ > yarn add serverless-stack-output
$ > npm install serverless-stack-output

Configuration

plugins:
  - serverless-stack-output

custom:
  output:
    handler: scripts/output.handler # Same syntax as you already know
    file: .build/stack.toml # toml, yaml, yml, and json format is available

Handler

Based on the configuration above the plugin will search for a file scripts/output.js with the following content:

function handler (data, serverless, options) {
  console.log('Received Stack Output', data)
}

module.exports = { handler }

File Formats

Just name your file with a .json, .toml, .yaml, or .yml extension, and the plugin will take care of formatting your output. Please make sure the location where you want to save the file exists!

License

Feel free to use the code, it's released using the MIT license.

Contribution

You are more than welcome to contribute to this project! ๐Ÿ˜˜ ๐Ÿ™†

To make sure you have a pleasant experience, please read the code of conduct. It outlines core values and believes and will make working together a happier experience.

Example

The plugins works fine with serverless functions, as well as when using custom CloudFormation resources. The following example configuration will deploy an AWS Lambda function, API Gateway, SQS Queue, IAM User with AccessKey and SecretKey, and a static value:

Serverless.yml

service: sls-stack-output-example

plugins:
  - serverless-stack-output

package:
  exclude:
    - node_modules/**

custom:
  output:
    handler: scripts/output.handler
    file: .build/stack.toml

provider:
  name: aws
  runtime: nodejs6.10

functions:
  example:
    handler: functions/example.handle
    events:
      - http:
          path: example
          method: get
          cors: true

resources:
  Resources:
    ExampleQueue:
      Type: AWS::SQS::Queue
      Properties:
        QueueName: example-queue
    ExampleUser:
      Type: "AWS::IAM::User"
      Properties:
        UserName: example-user
        Policies:
          - PolicyName: ExampleUserSQSPolicy
            PolicyDocument:
              Version: '2012-10-17'
              Statement:
                - Effect: "Allow"
                  Action:
                    - sqs:SendMessage
                  Resource:
                    - {"Fn::Join": [":", ["arn:aws:sqs:*", {"Ref": "AWS::AccountId"}, "example-queue"]]}
    ExampleUserKey:
      Type: AWS::IAM::AccessKey
      Properties:
        UserName:
          Ref: ExampleUser
  Outputs:
    ExampleUserKey:
      Value:
        Ref: ExampleUserKey
    ExampleUserSecret:
      Value: {"Fn::GetAtt": ["ExampleUserKey", "SecretAccessKey"]}
    ExampleStaticValue:
      Value: example-static-value

Stack Output

TOML

ExampleUserSecret = "YourUserSecretKey"
ExampleUserKey = "YourUserAccessKey"
ExampleLambdaFunctionQualifiedArn = "arn:aws:lambda:us-east-1:AccountID:function:sls-stack-output-example-dev-example:9"
ExampleStaticValue = "example-static-value"
ServiceEndpoint = "https://APIGatewayID.execute-api.us-east-1.amazonaws.com/dev"
ServerlessDeploymentBucketName = "sls-stack-output-example-serverlessdeploymentbuck-BucketID"

YAML

ExampleUserSecret: YourUserSecretKey
ExampleUserKey: YourUserAccessKey
ExampleLambdaFunctionQualifiedArn: 'arn:aws:lambda:us-east-1:AccountID:function:sls-stack-output-example-dev-example:9'
ExampleStaticValue: example-static-value
ServiceEndpoint: 'https://APIGatewayID.execute-api.us-east-1.amazonaws.com/dev'
ServerlessDeploymentBucketName: sls-stack-output-example-serverlessdeploymentbuck-BucketID

JSON

{
  "ExampleUserSecret": "YourUserSecretKey",
  "ExampleUserKey": "YourUserAccessKey",
  "ExampleLambdaFunctionQualifiedArn": "arn:aws:lambda:us-east-1:AccountID:function:sls-stack-output-example-dev-example:9",
  "ExampleStaticValue": "example-static-value",
  "ServiceEndpoint": "https://APIGatewayID.execute-api.us-east-1.amazonaws.com/dev",
  "ServerlessDeploymentBucketName": "sls-stack-output-example-serverlessdeploymentbuck-BucketID"
}

serverless-stack-output's People

Contributors

knakayama avatar sbstjn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

serverless-stack-output's Issues

Multiple outputs?

I've been using this and it works great, thanks. I'm curious if it's possible to generate the file output in multiple places? (One for react and one for node.)

[feature request] get expect output with command

Currently I can only generate the output (Stack Outputs) as output.json when run the command sls deploy with this plugin.

But I'd like to get the output (Stack Outputs) as json on-fly, for example, if I can run

sls info -v --output json
or
sls info -v -o json

That will be convenience.

cc: @sbstjn @anttiviljami

Babel

Is it possible to use babel to execute the code and thus can use ES6+ code i.e. modules

Fails silently if given directory path doesn't exist

When using a serverless.yml like:

plugins:
  - serverless-stack-output

custom:
  output:
    file: .serverless-outputs/stackOutput.json

Then if the given directory .serverless-outputs does not exists, it fails silently. I would expect any given folder that doesn't exist to be created, so we don't need to have a .gitkeep file in our repo.

Plugin executes out of order relative to other serverless plugins

Consider a serverless.yml

...
plugins:
    - serverless-stack-ouput
    - other-plugin

custom:
  output:
    file: stack-output.yml
...

where other-plugin processes stack-output.yml output by this file. As it's currently implemented, other-plugin will being processing before serverless-stack-output finished. The offending line is in the StackOutputPlugin#process method. If that method is changed to return a promise, everything works as expected.

how to generate the output file?

I followed the README and added plugin and custom parts in serverless.yml and I created scripts/output.js from example.

Then I run sls deploy.

No file .build/stack.toml was generated.

Any steps I missed?

feature required - output as shell source file

could I ask for a new format, that i can use the output as source file for shell script.

$ cat stack.sh

ExampleUserSecret="YourUserSecretKey"
ExampleUserKey="YourUserAccessKey"

Similar as TOML but no space around "="

so I can source it directly

.  stack.sh

plugin "serverless-stack-output" not found

Serverless Error ---------------------------------------

Serverless plugin "serverless-stack-output" not found. Make sure it's installed and listed in the "plugins" section of your serverless config file.

output from

sls plugin list
serverless-stack-output - Store output from your AWS CloudFormation Stack in JSON/YAML/TOML files, or to pass it to a JavaScript function for further processing.

config file and output file are exactly as in the ReadMe.md

Move hook to after:aws:deploy:deploy:updateStack rather than after:deploy:deploy

I'm attempting to have a single source project containing both React app and serverless spec, and have sls deploy:

  1. Deploy backend resources to AWS
  2. Use serverless-stack-output to update React app with details from CloudFormation
  3. Run npm build
  4. Use serverless-s3-sync to copy the React build/ directory up to S3.

Currently both serverless-stack-output and serverless-s3-sync run off after:deploy:deploy asynchronously. I'm not sure there's a way of defining the ordering or dependency between them without writing my own plugin, but it might be sufficient to move CloudFormation stack output earlier (and S3 sync later). Alternatively, is it related to #18?

I think this could be achieved by changing after:deploy:deploy to before:deploy:finalize in index.js.

I think this is sensible to go off the AWS-specific event, given it's specifically dealing with CloudFormation.

Custom stackName in next serverless version that will brake this plugin.

In serverless version above 1.27.3 one can set a custom stackName.

provider:
   stackName: my-custom-name

In main serverless they are using this getStackName from this code to fetch the stackname:
https://github.com/serverless/serverless/blob/cbc5e3c4e199a08650b02def8d1f9e91a13e7844/lib/plugins/aws/lib/naming.js

Used as in serverless, if you get the this reference correct you are done:

const stackname = this.provider.naming.getStackName();

Add custom domain to output

As a developer using the Serverless framework with the serverless-domain-manager plugin, I would like to have the name of my custom domain appear in the output file of the serverless-stack-output plugin, so I can target my post-deployment integration tests to the custom domain, instead of the API Gateway generated ServiceEndpoint.

Thank you for creating and maintaining this plugin!

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.