Last active
November 6, 2019 05:08
-
-
Save hideokamoto/3581ff5288bb4a0d964c7290f3565b55 to your computer and use it in GitHub Desktop.
AWS SDK(Node.js) snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CloudFront } from 'aws-sdk' | |
import DistributionSummaryList = CloudFront.DistributionSummaryList | |
const cfClient = new CloudFront() | |
/** | |
* @example | |
* const distributions = await listAllDistributions() | |
**/ | |
const listAllDistributions = async (distributions: DistributionSummaryList = [], Marker?: string): Promise<DistributionSummaryList> => { | |
const param: CloudFront.ListDistributionsRequest = {} | |
if (Marker) param.Marker = Marker | |
const { DistributionList } = await cfClient.listDistributions(param).promise() | |
if (!DistributionList || !DistributionList.Items) return distributions | |
const newLists = [ | |
...distributions, | |
...DistributionList.Items | |
] | |
if (!DistributionList.NextMarker) return newLists | |
return listAllDistributions(newLists, DistributionList.NextMarker) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment