UNPKG

2.22 kBMarkdownView Raw
1Serverless AWS Pseudo Parameters
2--------------------------------
3
4Currently, it's impossible (or at least, very hard) to use the [CloudFormation Pseudo Parameters](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html) in your `serverless.yml`.
5
6This plugin fixes that.
7
8You can now use `#{AWS::AccountId}`, `#{AWS::Region}`, etc. in any of your config strings, and this plugin replaces those values with the proper pseudo parameter `Fn::Sub` CloudFormation function.
9
10Installation
11-----
12Install the package with npm: `npm install serverless-pseudo-parameters`, and add it to your `serverless.yml` plugins list:
13
14```yaml
15plugins:
16 - serverless-pseudo-parameters
17```
18
19Usage
20-----
21Add one of the pseudo parameters to any resource parameter, and it will be replaced during deployment. Mind you to replace the default `${}` with a `#{}`. So `${AWS::AccountId}`, becomes: `#{AWS::AccountId}` etc.
22
23For example, this configuration will create a bucket with your account id appended to the bucket name:
24
25```yaml
26service: users-bucket-thingy
27
28plugins:
29 - serverless-pseudo-parameters
30
31functions:
32 users:
33 handler: users.handler
34 events:
35 - s3:
36 bucket: photos-#{AWS::AccountId}
37 event: s3:ObjectRemoved:*
38```
39
40The output in the cloudformation template will look something like this:
41
42```json
43"Type": "AWS::S3::Bucket",
44"Properties": {
45 "BucketName": {
46 "Fn::Sub": "photos-${AWS::AccountId}"
47 },
48}
49```
50
51Or use it to generate Arn's, for example for [Step Functions](https://www.npmjs.com/package/serverless-step-functions):
52
53```yaml
54service: foobar-handler
55
56plugins:
57 - serverless-pseudo-parameters
58
59functions:
60 foobar-baz:
61 handler: foo.handler
62
63stepFunctions:
64 stateMachines:
65 foobar:
66 definition:
67 Comment: "Foo!"
68 StartAt: bar
69 States:
70 bar:
71 Type: Task
72 Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${opt:stage}-foobar-baz"
73 End: true
74```
75
76The plugin also automatically replace _hardcoded_ region in `serverless.yml`. This feature can be disabled using:
77
78```yaml
79custom:
80 pseudoParameters:
81 skipRegionReplace: true
82```