1 | Serverless AWS Pseudo Parameters
|
2 | --------------------------------
|
3 |
|
4 | Currently, 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 |
|
6 | This plugin fixes that.
|
7 |
|
8 | You can now use `#{AWS::AccountId}` etc. in any of your config strings, and this plugin replaces those values with the proper pseudo parameter `Fn::Sub` CloudFormation function.
|
9 |
|
10 | Installation
|
11 | -----
|
12 | Install the package with npm: `npm install serverless-pseudo-parameters`, and add it to your `serverless.yml` plugins list:
|
13 |
|
14 | ```
|
15 | plugins:
|
16 | - serverless-pseudo-parameters
|
17 | ```
|
18 |
|
19 | Usage
|
20 | -----
|
21 | Add 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 |
|
23 | For example, this configuration will create a bucket with your account id appended to the bucket name:
|
24 |
|
25 | ```
|
26 | service: users-bucket-thingy
|
27 |
|
28 | plugins:
|
29 | - serverless-pseudo-parameters
|
30 |
|
31 | functions:
|
32 | users:
|
33 | handler: users.handler
|
34 | events:
|
35 | - s3:
|
36 | bucket: photos-#{AWS::AccountId}
|
37 | event: s3:ObjectRemoved:*
|
38 | ```
|
39 |
|
40 | The output in the cloudformation template will look something like this:
|
41 |
|
42 | ```
|
43 | "Type": "AWS::S3::Bucket",
|
44 | "Properties": {
|
45 | "BucketName": {
|
46 | "Fn::Sub": "photos-${AWS::AccountId}"
|
47 | },
|
48 | }
|
49 | ```
|
50 |
|
51 | Or use it to generate Arn's, for example for [Step Functions](https://www.npmjs.com/package/serverless-step-functions):
|
52 |
|
53 | ```
|
54 | service: foobar-handler
|
55 |
|
56 | plugins:
|
57 | - serverless-pseudo-parameters
|
58 |
|
59 | functions:
|
60 | foobar-baz:
|
61 | handler: foo.handler
|
62 |
|
63 | stepFunctions:
|
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 | ```
|