Skip to content

Commit 6abde8d

Browse files
committed
Fix CloudFormation generation
1 parent 6026947 commit 6abde8d

File tree

4 files changed

+27
-30
lines changed

4 files changed

+27
-30
lines changed

README.md

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,25 @@ functions:
4242
...
4343
```
4444
45-
During pre-processing the `${fn.*}` related items will be resolved resulting in
46-
the below CloudFormation snippet.
47-
48-
```yaml
49-
service: test
50-
51-
plugins:
52-
- serverless-plugin-function-value
53-
54-
provider:
55-
name: aws
56-
...
57-
58-
resources:
59-
Resources:
60-
LambdaFunctionExecutor:
61-
Type: Custom::LambdaFunctionExecutor
62-
Properties:
63-
ServiceToken: !GetAtt HealthLambdaFunction.Arn # resolved
64-
Name: !Ref HealthLambdaFunction # resolved
65-
66-
functions:
67-
health:
68-
...
45+
During processing the `${fn.*}` related items will be resolved to either the
46+
`Fn::GetAtt` for `${fn.arn:*}` or `Ref` for `${fn.name:*}`. The custom resource
47+
above would look like the below in the generated CloudForamtion template.
48+
49+
```json
50+
"LambdaFunctionExecutor": {
51+
"Type": "Custom::LambdaFunctionExecutor",
52+
"Properties": {
53+
"ServiceToken": {
54+
"Fn::GetAtt": [
55+
"HealthLambdaFunction",
56+
"Arn"
57+
]
58+
},
59+
"Name": {
60+
"Ref": "HealthLambdaFunction"
61+
}
62+
}
63+
}
6964
```
7065

7166
## Development

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-plugin-function-value",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Serverless framework plugin that will automatically generate CloudFormation snippets to reference a functions name or arn value based on the generated logical ID used during creation of the CloudFormation templates",
55
"main": "dist/index.js",
66
"scripts": {

src/function-value-plugin.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ export class FunctionValuePlugin {
2121
}
2222

2323
getFunctionArnStatement(value) {
24-
return Promise.resolve(`!GetAtt ${this.getFunctionLogicalId(value)}.Arn`);
24+
return Promise.resolve({
25+
'Fn::GetAtt': [this.getFunctionLogicalId(value), 'Arn']
26+
});
2527
}
2628

2729
getFunctionNameStatement(value) {
28-
return Promise.resolve(`!Ref ${this.getFunctionLogicalId(value)}`);
30+
return Promise.resolve({ Ref: this.getFunctionLogicalId(value) });
2931
}
3032
}

test/function-value-plugin.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ describe('plugin', () => {
2020
});
2121

2222
[
23-
{ type: 'arn', expected: `!GetAtt ${logicalId}.Arn` },
24-
{ type: 'name', expected: `!Ref ${logicalId}` }
23+
{ type: 'arn', expected: { 'Fn::GetAtt': [logicalId, 'Arn'] } },
24+
{ type: 'name', expected: { Ref: logicalId } }
2525
].forEach(test => {
2626
it(`will generate function ${test.type} snippet`, async () => {
2727
const resolver = `fn.${test.type}`;
2828
const value = `${resolver}:${functionName}`;
2929
const result = await variableResolvers[resolver](value);
3030

31-
expect(result).to.equal(test.expected);
31+
expect(result).to.deep.equal(test.expected);
3232
});
3333
});
3434

0 commit comments

Comments
 (0)