Send logs to CloudWatch logs
@dylburger
code:
data:privatelast updated:2 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 800,000+ developers using the Pipedream platform
steps.
trigger
HTTP API
Deploy to generate unique URL
This workflow runs on Pipedream's servers and is triggered by HTTP / Webhook requests.
steps.
logs
auth
to use OAuth tokens and API keys in code via theauths object
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) => {
1
2
3
4
5
6
7
}
8
return [
  {
    timestamp: +new Date(steps.trigger.context.ts),
    message: "Hello, world"
  }
]
steps.
CONSTANTS
auth
to use OAuth tokens and API keys in code via theauths object
params
CloudWatch Log group name
 
string ·params.logGroupName
CloudWatch Log stream name
 
string ·params.logStreamName
AWS Region
 
string ·params.region
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) => {
1
2
3
4
}
5
this.logGroupName = params.logGroupName
this.logStreamName = params.logStreamName
this.awsRegion = params.region
steps.
get_next_sequence_token
auth
to use OAuth tokens and API keys in code via theauths object
(auths.aws)
params
Region
 
string ·params.region
Log group name
 
string ·params.logGroupName
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
// We need to pass a "sequence token" to CloudWatch to write logs to a specicic stream.
// From the AWS docs:
// "The sequence token obtained from the response of the previous PutLogEvents call. 
// An upload in a newly created log stream does not need a sequence token. 
// You can also get the sequence token using DescribeLogStreams"
const AWS = require("aws-sdk")
const { accessKeyId, secretAccessKey } = auths.aws

const logs = new AWS.CloudWatchLogs({
  accessKeyId, 
  secretAccessKey,
  region: params.region,
})

const { logStreams } = await logs.describeLogStreams({
  logGroupName: params.logGroupName,
}).promise()

// Find our target log stream, and return its sequence token
const stream = logStreams.find(s => s.logStreamName === steps.CONSTANTS.logStreamName)
return stream?.uploadSequenceToken
steps.
cloudwatch_logs_put_log_events

Uploads a batch of log events to the specified log stream. See the docs for more information

configure

The AWS region string where you'd like to create your SNS topic

us-east-1

The name of the log group you'd like to write logs to

The name of the log stream within your log group

An array of log events. Each log event must contain a timestamp (the time the event occurred) and a message. See the docs

[0]:
 
Enter a value for Log data

The sequence token obtained from the response of the previous PutLogEvents call. An upload in a newly created log stream does not need a sequence token. You can also get the sequence token using DescribeLogStreams. If you call PutLogEvents twice within a narrow time period using the same value for sequenceToken, both calls might be successful or one might be rejected.

 
Enter a value for Sequence token