Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 7b9232e

Browse files
committed
add additional methods
1 parent 220534d commit 7b9232e

7 files changed

+232
-21
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ const s3 = new aws.S3({
1212
region: 'us-east-1'
1313
})
1414

15-
// initialize the Extra service for extra methods
16-
const extra = new aws.Extra({
15+
// initialize the Extras service for extra methods
16+
const extras = new aws.Extras({
1717
credentials: { accessKeyId: 'xxx', secretAccessKey: 'xxx' },
1818
region: 'us-east-1'
1919
})
2020

2121
// call some powerful extra methods. More info below.
22-
const certificate = await extra.deployCertificate(params)
22+
const certificate = await extras.deployCertificate(params)
2323
```
2424

2525
# Reference
@@ -54,7 +54,7 @@ const {
5454
certificateArn,
5555
certificateStatus,
5656
domainHostedZoneId
57-
} = await extra.deployDistributionDomain(params)
57+
} = await extras.deployDistributionDomain(params)
5858
```
5959

6060
# deployCertificate
@@ -66,7 +66,7 @@ const params = {
6666
domain: 'serverless.com'
6767
}
6868

69-
const { certificateArn, certificateStatus, domainHostedZoneId } = await extra.deployCertificate(
69+
const { certificateArn, certificateStatus, domainHostedZoneId } = await extras.deployCertificate(
7070
params
7171
)
7272
```
@@ -81,7 +81,7 @@ const params = {
8181
distributionUrl: 'xxx.cloudfront.net'
8282
}
8383

84-
const { domainHostedZoneId } = await extra.deployDistributionDns(params)
84+
const { domainHostedZoneId } = await extras.deployDistributionDns(params)
8585
```
8686

8787
# addDomainToDistribution
@@ -95,7 +95,7 @@ const params = {
9595
certificateStatus: 'ISSUED'
9696
}
9797

98-
const { domainHostedZoneId } = await extra.addDomainToDistribution(params)
98+
const { domainHostedZoneId } = await extras.addDomainToDistribution(params)
9999
```
100100

101101
# getDomainHostedZoneId
@@ -107,7 +107,7 @@ const params = {
107107
domain: 'serverless.com'
108108
}
109109

110-
const { domainHostedZoneId } = await extra.getDomainHostedZoneId(params)
110+
const { domainHostedZoneId } = await extras.getDomainHostedZoneId(params)
111111
```
112112

113113
# deployRole
@@ -131,7 +131,7 @@ const params = {
131131
}
132132
]
133133
}
134-
const { roleArn } = await extra.deployRole(params)
134+
const { roleArn } = await extras.deployRole(params)
135135
```
136136

137137
Or you can specify the policy as a maanged policy arn string:
@@ -142,7 +142,7 @@ const params = {
142142
service: 'lambda.amazonaws.com',
143143
policy: 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
144144
}
145-
const { roleArn } = await extra.deployRole(params)
145+
const { roleArn } = await extras.deployRole(params)
146146
```
147147

148148
If you don't specify a policy property, an admin policy will be created by default.
@@ -156,7 +156,7 @@ const params = {
156156
name: 'my-role'
157157
}
158158

159-
await extra.removeRole(params)
159+
await extras.removeRole(params)
160160
```
161161

162162
# removeRolePolicies
@@ -168,7 +168,7 @@ const params = {
168168
name: 'my-role'
169169
}
170170

171-
await extra.removeRolePolicies(params)
171+
await extras.removeRolePolicies(params)
172172
```
173173

174174
# deployLambda
@@ -189,7 +189,7 @@ const params = {
189189
- subnet-xxx
190190
}
191191

192-
const { lambdaArn, lambdaSize, lambdaSha } = await extra.deployLambda(params)
192+
const { lambdaArn, lambdaSize, lambdaSha } = await extras.deployLambda(params)
193193
```
194194

195195
# deployApigDomainDns
@@ -203,7 +203,7 @@ const params = {
203203
apigatewayDomainName: 'd-qwertyuiop.xxx.com' // required. The regional endpoint of the APIG custom domain
204204
}
205205

206-
const { domainHostedZoneId } = await extra.deployApigDomainDns(params)
206+
const { domainHostedZoneId } = await extras.deployApigDomainDns(params)
207207
```
208208

209209
# deployAppSyncApi
@@ -216,7 +216,7 @@ const params = {
216216
apiId: 'xxx' // if provided, updates the API. If not provided, creates a new API
217217
}
218218

219-
const { apiId, apiUrls } = await extra.deployAppSyncApi(params)
219+
const { apiId, apiUrls } = await extras.deployAppSyncApi(params)
220220
```
221221

222222
# deployAppSyncSchema
@@ -229,7 +229,7 @@ const params = {
229229
schema: '...' // valid graphql schema
230230
}
231231

232-
await extra.deployAppSyncApi(params)
232+
await extras.deployAppSyncApi(params)
233233
```
234234

235235
# deployAppSyncResolvers
@@ -254,7 +254,7 @@ const params = {
254254
}
255255
}
256256

257-
await extra.deployAppSyncResolvers(params)
257+
await extras.deployAppSyncResolvers(params)
258258
```
259259

260260
# deployStack
@@ -297,7 +297,7 @@ const inputs = {
297297
role: 'arn:iam:xxx'
298298
}
299299

300-
const outputs = await extra.deployStack(params)
300+
const outputs = await extras.deployStack(params)
301301
```
302302

303303
# removeStack
@@ -309,5 +309,5 @@ const prams = {
309309
stackName: 'my-stack' // name of the stack you want to remove
310310
}
311311

312-
await extra.removeStack(params)
312+
await extras.removeStack(params)
313313
```

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@serverless/aws-sdk-extra",
3-
"version": "1.0.0",
3+
"version": "1.1.0-beta.1",
44
"description": "The AWS SDK that includes with a handful of extra convenience methods.",
55
"main": "src/index.js",
66
"author": "Serverless, Inc.",
@@ -27,4 +27,4 @@
2727
"eslint-plugin-prettier": "^3.1.0",
2828
"prettier": "^1.18.2"
2929
}
30-
}
30+
}

src/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ const removeDistribution = require('./removeDistribution')
3232
const getMetrics = require('./getMetrics')
3333
const deployStack = require('./deployStack')
3434
const removeStack = require('./removeStack')
35+
const listAllAwsRegions = require('./listAllAwsRegions')
36+
const listAllCloudFormationStacksInARegion = require('./listAllCloudFormationStacksInARegion')
37+
const listAllCloudFormationStacksInAllRegions = require('./listAllCloudFormationStacksInAllRegions')
38+
const listAllCloudFormationStackResources = require('./listAllCloudFormationStackResources')
3539

3640
/**
3741
* Define AWS Extras class
@@ -309,6 +313,34 @@ class Extras {
309313
removeStack(params) {
310314
return removeStack(this.config, params)
311315
}
316+
317+
/**
318+
* List all AWS Regions currently available, formatted for SDK input, in an array
319+
*/
320+
listAllAwsRegions() {
321+
return listAllAwsRegions()
322+
}
323+
324+
/**
325+
* Performs one or multiple API requests until all AWS CloudFormation Stacks are collected within a specified region and returned in an array.
326+
*/
327+
listAllCloudFormationStacksInARegion(params) {
328+
return listAllCloudFormationStacksInARegion(this.config, params)
329+
}
330+
331+
/**
332+
* Performs one or multiple API requests until all AWS CloudFormation Stacks in all regions are collected and returned in an array.
333+
*/
334+
listAllCloudFormationStacksInAllRegions(params) {
335+
return listAllCloudFormationStacksInAllRegions(this.config, params)
336+
}
337+
338+
/**
339+
* Performs one or multiple API requests until summaries for all resources in an AWS CloudFormation Stack are collected and returned as an array.
340+
*/
341+
listAllCloudFormationStackResources(params) {
342+
return listAllCloudFormationStackResources(this.config, params)
343+
}
312344
}
313345

314346
/**

src/listAllAwsRegions.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = () => {
2+
return [
3+
'us-east-1',
4+
'us-east-2',
5+
'us-west-1',
6+
'us-west-2',
7+
'af-south-1',
8+
'ap-east-1',
9+
'ap-south-1',
10+
'ap-northeast-1',
11+
'ap-northeast-2',
12+
'ap-southeast-1',
13+
'ap-southeast-2',
14+
'ca-central-1',
15+
'cn-north-1',
16+
'cn-northwest-1',
17+
'eu-central-1',
18+
'eu-west-1',
19+
'eu-west-2',
20+
'eu-west-3',
21+
'eu-south-1',
22+
'eu-north-1',
23+
'me-south-1',
24+
'sa-east-1',
25+
'us-gov-east-1',
26+
'us-gov-west-1',
27+
]
28+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const AWS = require('aws-sdk')
2+
3+
const listAllCloudFormationStackResources = async (
4+
config,
5+
{
6+
region = null,
7+
stackName = null,
8+
nextToken = null,
9+
},
10+
resources = []) => {
11+
12+
if (!stackName) {
13+
throw new Error(`Missing "stackName" param.`)
14+
}
15+
if (!config.region && !region) {
16+
throw new Error(`Either config.region must be set or the 'region' parameter must be submitted`)
17+
}
18+
19+
config.region = config.region || region
20+
21+
// Fetch stacks
22+
const cloudformation = new AWS.CloudFormation(config)
23+
24+
const params = {
25+
StackName: stackName,
26+
NextToken: nextToken,
27+
}
28+
29+
const res = await cloudformation.listStackResources(params).promise();
30+
31+
// Concatenate stacks
32+
if (res.StackResourceSummaries && res.StackResourceSummaries.length) {
33+
resources = resources.concat(resources, res.StackResourceSummaries);
34+
}
35+
36+
// If NextToken, call again...
37+
if (res.NextToken) {
38+
return await listAllCloudFormationStackResources(
39+
config,
40+
{
41+
stackName,
42+
nextToken: res.NextToken,
43+
},
44+
resources
45+
);
46+
}
47+
48+
return resources
49+
}
50+
51+
module.exports = listAllCloudFormationStackResources
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const AWS = require('aws-sdk')
2+
3+
const listAllCloudFormationStacksInARegion = async (
4+
config,
5+
{
6+
region = null,
7+
nextToken = null,
8+
stackStatusFilter = null
9+
},
10+
stacks = []) => {
11+
12+
if (!region) {
13+
throw new Error(`Missing "region" param.`)
14+
}
15+
16+
// Override region configuration
17+
config.region = region
18+
19+
// Default to Stacks with an Active state, defined by these status values
20+
stackStatusFilter = stackStatusFilter || [
21+
'CREATE_COMPLETE',
22+
'UPDATE_COMPLETE',
23+
'ROLLBACK_COMPLETE',
24+
'IMPORT_COMPLETE',
25+
'IMPORT_ROLLBACK_COMPLETE',
26+
]
27+
28+
// Fetch stacks
29+
const cloudformation = new AWS.CloudFormation(config)
30+
31+
const params = {
32+
NextToken: nextToken,
33+
StackStatusFilter: stackStatusFilter,
34+
}
35+
36+
const res = await cloudformation.listStacks(params).promise();
37+
38+
// Concatenate stacks
39+
if (res.StackSummaries && res.StackSummaries.length) {
40+
41+
// Add region to each
42+
res.StackSummaries.forEach((summary) => {
43+
summary.Region = region
44+
})
45+
46+
stacks = stacks.concat(stacks, res.StackSummaries);
47+
}
48+
49+
// If NextToken, call again...
50+
if (res.NextToken) {
51+
return await listAllCloudFormationStacksInARegion(
52+
config,
53+
{
54+
region,
55+
nextToken: res.NextToken,
56+
stackStatusFilter,
57+
},
58+
stacks
59+
);
60+
}
61+
62+
return stacks
63+
}
64+
65+
module.exports = listAllCloudFormationStacksInARegion

0 commit comments

Comments
 (0)