mvila / serverless-plugin-scripts

Add scripting capabilities to the Serverless Framework
123 stars 15 forks source link

inject stack outputs to script? #1

Closed tommedema closed 7 years ago

tommedema commented 7 years ago

how would you inject the output of your cloudformation stack, e.g. ServiceEndpoint, to a build script for post processing? e.g. to dynamically inject the api endpoint into your frontend

mvila commented 7 years ago

I think you can do that using variables:

https://serverless.com/framework/docs/providers/aws/guide/variables/

tommedema commented 7 years ago

@mvila I thought so too but failed to achieve the desired result

tommedema commented 7 years ago

Ultimately I did it like so:

serverless.yml

custom:

  scriptHooks:
    after:aws:info:gatherData: scripts/compile-web.js

compile-web.js

/* global serverless */

console.log('compiling web package with cloudformation outputs')

const awsInfo = serverless.pluginManager.plugins.find(p => p.constructor.name === 'AwsInfo')
const getOutput = key => awsInfo.gatheredData.outputs.find(o => o.OutputKey === key).OutputValue
const gatewayUrl = getOutput('ServiceEndpoint')
console.log(gatewayUrl)

Note that this is using https://github.com/weixu365/serverless-scriptable-plugin

Seems rather hackish though.

mvila commented 7 years ago

I agree, it doesn't look very clean. I am sorry but I am afraid I cannot help you more on that. Actually, I stopped using Serverless Framework...