Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect custom stack name #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class ServerlessResourcesEnv {
* @returns {Promise.<TResult>}
*/
afterDeploy() {
const stackName = this.getStackName();

// First fetch all of our Resources from AWS by doing a network call
return this.fetchCFResources().then((resourceResult) => {
// Map these to an object keyed by the Logical id pointing to the PhysicalId
Expand All @@ -57,7 +55,7 @@ class ServerlessResourcesEnv {

// For each function, update the env files on that function.
const updatePromises = _.map(_.keys(this.serverless.service.functions), (functionName) => {
const awsFunctionName = `${stackName}-${functionName}`;
const awsFunctionName = `${this.serverless.service.service}-${this.getStage()}-${functionName}`;
const resourceList = _.map(
this.serverless.service.functions[functionName].custom &&
this.serverless.service.functions[functionName].custom['env-resources'],
Expand Down Expand Up @@ -250,7 +248,11 @@ class ServerlessResourcesEnv {
* @returns {string}
*/
getStackName() {
return `${this.serverless.service.service}-${this.getStage()}`;
let returnValue = `${this.serverless.service.service}-${this.getStage()}`;
if (this.serverless.service.provider.stackName) {
returnValue = this.serverless.service.provider.stackName;
}
return returnValue;
}
}

Expand Down
9 changes: 9 additions & 0 deletions test/plugin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ describe('serverless-fetch-stack-resource', () => {
}), { stage: 'from_option' });
expect(instance.getStackName()).to.equal('a_service-from_option');
});

it('uses stack name of config provider if set', () => {
const instance = new ServerlessFetchStackResources(
_.extend({}, serverlessStub, {
config: {},
service: { service: 'a_service', provider: { stackName: 'stack_name' } },
}), { stage: 'from_option' });
expect(instance.getStackName()).to.equal('stack_name-from_option');
});
});

describe('fetchCFResources', () => {
Expand Down