Skip to content

Commit 65064f4

Browse files
committed
Fixed #5
1 parent f54896a commit 65064f4

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ class ServerlessStepFunctions {
166166
getIamRoleName() {
167167
let name = `${this.service}-${this.region}-${this.stage}-${this.options.state}-`;
168168
name += 'ssf-exerole';
169-
return name;
169+
return name.substr(0, 64);
170170
}
171171

172172
getIamPolicyName() {
173173
let name = `${this.service}-${this.region}-${this.stage}-${this.options.state}-`;
174174
name += 'ssf-exepolicy';
175-
return name;
175+
return name.substr(0, 64);
176176
}
177177

178178
getStateMachineName() {
@@ -403,15 +403,14 @@ class ServerlessStepFunctions {
403403
throw new this.serverless.classes.Error(errorMessage);
404404
}
405405

406-
_.forEach(this.stepFunctions[this.options.state].States, (value, key) => {
407-
if (value.Resource && !value.Resource.match(/arn:aws:lambda/)) {
408-
this.stepFunctions[this.options.state].States[key].Resource
409-
= this.functionArns[value.Resource];
410-
}
411-
});
412-
413406
this.awsStateLanguage[this.options.state] =
414407
JSON.stringify(this.stepFunctions[this.options.state]);
408+
409+
_.forEach(this.functionArns, (value, key) => {
410+
const regExp = new RegExp(`"Resource":"${key}"`, 'g');
411+
this.awsStateLanguage[this.options.state] =
412+
this.awsStateLanguage[this.options.state].replace(regExp, `"Resource":"${value}"`);
413+
});
415414
return BbPromise.resolve();
416415
}
417416
}

index.test.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ describe('ServerlessStepFunctions', () => {
476476
});
477477

478478
describe('#compile()', () => {
479-
beforeEach(() => {
479+
it('should comple with correct params', () => {
480480
serverlessStepFunctions.stepFunctions = {
481481
stateMachine: {
482482
States: {
@@ -487,17 +487,36 @@ describe('ServerlessStepFunctions', () => {
487487
},
488488
};
489489
serverlessStepFunctions.functionArns.first = 'lambdaArn';
490-
});
491-
492-
it('should comple with correct params'
493-
, () => serverlessStepFunctions.compile()
494-
.then(() => {
495-
expect(serverlessStepFunctions.stepFunctions.stateMachine.States.HelloWorld.Resource)
496-
.to.be.equal('lambdaArn');
490+
serverlessStepFunctions.compile().then(() => {
497491
expect(serverlessStepFunctions.awsStateLanguage.stateMachine)
498492
.to.be.equal('{"States":{"HelloWorld":{"Resource":"lambdaArn"}}}');
499-
})
500-
);
493+
});
494+
});
495+
496+
it('should comple with correct params when nested Resource', () => {
497+
serverlessStepFunctions.stepFunctions = {
498+
stateMachine: {
499+
States: {
500+
HelloWorld: {
501+
Resource: 'first',
502+
HelloWorld: {
503+
Resource: 'first',
504+
HelloWorld: {
505+
Resource: 'first',
506+
},
507+
},
508+
},
509+
},
510+
},
511+
};
512+
513+
let a = '{"States":{"HelloWorld":{"Resource":"lambdaArn","HelloWorld"';
514+
a += ':{"Resource":"lambdaArn","HelloWorld":{"Resource":"lambdaArn"}}}}}';
515+
serverlessStepFunctions.functionArns.first = 'lambdaArn';
516+
serverlessStepFunctions.compile().then(() => {
517+
expect(serverlessStepFunctions.awsStateLanguage.stateMachine).to.be.equal(a);
518+
});
519+
});
501520
});
502521
});
503522

0 commit comments

Comments
 (0)