Skip to content

Commit b62e226

Browse files
authored
Merge pull request #2 from adambartholomew/task-resource-mapping
Performing resource replacements for localhost using TaskResourceMappings
2 parents 5fc3736 + 0724a1e commit b62e226

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 0.1.3
2+
3+
- Allow for resource replacements for local development using custom `TaskResourceMapping` configuration

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ It also adds an environment variable for each created state machine that contain
5151
- `region` (required) your AWS region
5252
- `lambdaEndpoint` (defaults to `http://localhost:4000`) the endpoint for the lambda service
5353
- `path` (defaults to `./.step-functions-local`) the path to store the downloaded step function executables
54+
- `TaskResourceMapping` allows for Resource ARNs to be configured differently for local development
5455

5556
### Full Config Example
5657

@@ -72,6 +73,9 @@ custom:
7273
stepFunctionsLocal:
7374
accountId: 101010101010
7475
region: us-east-1
76+
TaskResourceMapping:
77+
FirstState: arn:aws:lambda:us-east-1:101010101010:function:hello
78+
FinalState: arn:aws:lambda:us-east-1:101010101010:function:hello
7579
7680
functions:
7781
hello:
@@ -86,14 +90,14 @@ stepFunctions:
8690
States:
8791
FirstState:
8892
Type: Task
89-
Resource: arn:aws:lambda:us-east-1:101010101010:function:hello
93+
Resource: Fn::GetAtt: [hello, Arn]
9094
Next: wait_using_seconds
9195
wait_using_seconds:
9296
Type: Wait
9397
Seconds: 10
9498
Next: FinalState
9599
FinalState:
96100
Type: Task
97-
Resource: arn:aws:lambda:us-east-1:101010101010:function:hello
101+
Resource: Fn::GetAtt: [hello, Arn]
98102
End: true
99103
```

index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,28 @@ class ServerlessStepFunctionsLocal {
7979
const parsed = await this.serverless.yamlParser.parse(configPath);
8080

8181
this.stateMachines = parsed.stepFunctions.stateMachines;
82+
83+
if (parsed.custom
84+
&& parsed.custom.stepFunctionsLocal
85+
&& parsed.custom.stepFunctionsLocal.TaskResourceMapping) {
86+
this.replaceTaskResourceMappings(parsed.stepFunctions.stateMachines, parsed.custom.stepFunctionsLocal.TaskResourceMapping);
87+
}
88+
}
89+
90+
/**
91+
* Replaces Resource properties with values mapped in TaskResourceMapping
92+
*/
93+
replaceTaskResourceMappings(input, replacements, parentKey) {
94+
for(var key in input) {
95+
var property = input[key];
96+
if (['object', 'array'].indexOf(typeof property) > -1) {
97+
if (input['Resource'] && replacements[parentKey]) {
98+
input['Resource'] = replacements[parentKey];
99+
}
100+
// Recursive replacement of nested states
101+
this.replaceTaskResourceMappings(property, replacements, key);
102+
}
103+
}
82104
}
83105

84106
async createEndpoints() {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-step-functions-local",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "Run AWS step functions offline with Serverless",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)