Skip to content

Instantly share code, notes, and snippets.

@hideokamoto
Last active November 6, 2019 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hideokamoto/3581ff5288bb4a0d964c7290f3565b55 to your computer and use it in GitHub Desktop.
Save hideokamoto/3581ff5288bb4a0d964c7290f3565b55 to your computer and use it in GitHub Desktop.
AWS SDK(Node.js) snippets
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