Take a screenshot with Puppet Master, save to S3
@dylburger
code:
data:privatelast updated:4 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 1,000,000+ developers using the Pipedream platform
steps.
trigger
Cron Scheduler
Deploy to configure a custom schedule
This workflow runs on Pipedream's servers and is triggered on a custom schedule.
steps.
take_screenshot
auth
to use OAuth tokens and API keys in code via theauths object
(auths.puppet_master)
params
URL

Take a screenshot of this URL

 
https://example.com
string ·params.url
Optional
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps, params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
}
38
const axios = require('axios')

const type = params.type || 'png'

const config = {
  method: 'GET',
  url: 'https://ssfy.sh/dev/puppet-master@6cc8d95d/screenshot',
  params: {
    url: params.url,
    type,
    fullPage: params.fullPage,
    omitBackground: params.omitBackground,
    clip: params.clip,
    gotoOptions: params.gotoOptions,
    viewport: params.viewport,
    userAgent: params.userAgent,
    emulateDevice: params.emulateDevice,
  },
  responseType: 'arraybuffer',
}

// If you get rate limited, you can sign up for an API key here:
// https://puppet-master.sh/pricing
if (params.api_key) config.headers['Authorization'] = params.api_key

const resp = await axios(config)
this.screenshot = resp.data.toString('base64')

// Export the rate limit data for debugging
const { headers } = resp
this.remaining_rate_limit = headers["x-ratelimit-remaining"]
this.rate_limit_reset_in = `Rate limit resets in ${(((headers["x-ratelimit-reset"] * 1000) - +new Date()) / 1000 / 60)} minutes`

// Pass the URL to the next step as the filename
this.url = params.url
this.type = type
steps.
save_to_s3
auth
to use OAuth tokens and API keys in code via theauths object
(auths.aws)
params
Bucket
 
string ·params.bucket
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps, params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
}
23
const AWS = require("aws-sdk")

const { bucket } = params
const { url, screenshot, type } = steps.take_screenshot
const { accessKeyId, secretAccessKey } = auths.aws

const s3 = new AWS.S3({
  accessKeyId, 
  secretAccessKey,
})

// Store screenshot at object tied to site + current epoch
const Key = `${url.replace(/[&\/\\#, +()$~%.'":*?<>{}]/g, '_')}-${+new Date()}.${type}`
const uploadParams = { 
  Bucket: bucket, 
  Key, 
  Body: Buffer.from(screenshot, 'base64'),
  ContentType: `image/${type}`
}
this.S3Response = await s3.upload(uploadParams).promise()
console.log(`Uploaded file to S3!`)