Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const cloud = require("@pulumi/cloud-aws");
// Create a mapping from 'route' to a count
let counterTable = new cloud.Table("counterTable", "route");
// Create an API endpoint
let endpoint = new cloud.API("hello-world");
endpoint.get("/{route+}", (req, res) => {
let route = req.params["route"];
console.log(`Getting count for '${route}'`);
// get previous value and increment
// reference outer `counterTable` object
counterTable.get({ route }).then(value => {
let count = (value && value.count) || 0;
counterTable.insert({ route, count: ++count }).then(() => {
res.status(200).json({ route, count });
console.log(`Got count ${count} for '${route}'`);
});
});
});
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
// Note: @pulumi/cloud is a preview package demonstrating how to create cross-cloud Pulumi
// components. If you are targeting a specific cloud like AWS, Azure, or GCP, we recommend you use
// platform-specific packages like @pulumi/aws, @pulumi/azure or @pulumi/gcp. These packages give
// you full access to the breadth of the platform's capabilities and comes with many abstractions to
// make developing against that platform easier.
import * as cloud from "@pulumi/cloud-aws";
// Create a web server.
const endpoint = new cloud.API("urlshortener");
// Create a table `urls`, with `name` as primary key.
const urlTable = new cloud.Table("urls", "name");
// Serve all files in the www directory to the root.
endpoint.static("/", "www");
// GET /url lists all URLs currently registered.
endpoint.get("/url", async (req, res) => {
try {
const items = await urlTable.scan();
res.status(200).json(items);
console.log(`GET /url retrieved ${items.length} items`);
} catch (err) {
res.status(500).json(err.stack);
console.log(`GET /url error: ${err.stack}`);
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
"use strict";
const cloud = require("@pulumi/cloud-aws");
const video = require("./video-label-processor");
// A bucket to store videos and thumbnails.
const bucket = new cloud.Bucket("bucket");
const bucketName = bucket.bucket.id;
// A task which runs a containerized FFMPEG job to extract a thumbnail image.
const ffmpegThumbnailTask = new cloud.Task("ffmpegThumbTask", {
build: "./docker-ffmpeg-thumb",
memoryReservation: 512,
});
// Use module for processing video through Rekognition
const videoProcessor = new video.VideoLabelProcessor();
// When a new video is uploaded, start Rekognition label detection
bucket.onPut("onNewVideo", bucketArgs => {
console.log(`*** New video: file ${bucketArgs.key} was uploaded at ${bucketArgs.eventTime}.`);
videoProcessor.startRekognitionJob(bucketName.get(), bucketArgs.key);
return Promise.resolve();
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
const cloud = require("@pulumi/cloud-aws");
// A bucket to store videos and thumbnails.
const bucket = new cloud.Bucket("bucket");
const bucketName = bucket.bucket.id;
// A task which runs a containerized FFMPEG job to extract a thumbnail image.
const ffmpegThumbnailTask = new cloud.Task("ffmpegThumbTask", {
build: "./docker-ffmpeg-thumb",
memoryReservation: 512,
});
// When a new video is uploaded, run the FFMPEG task on the video file.
// Use the time index specified in the filename (e.g. cat_00-01.mp4 uses timestamp 00:01)
bucket.onPut("onNewVideo", bucketArgs => {
console.log(`*** New video: file ${bucketArgs.key} was uploaded at ${bucketArgs.eventTime}.`);
const file = bucketArgs.key;
const thumbnailFile = file.substring(0, file.indexOf('_')) + '.jpg';
const framePos = file.substring(file.indexOf('_')+1, file.indexOf('.')).replace('-',':');
console.log(now);
res.status(200).end(now.toString());
});
endpoint.post("/echo", async (req, res) => {
const data = parseUrlEncodedBody(req.body);
const response: SlackSlashCommandResponse = {
response_type: "in_channel",
text: data.text,
};
res.status(200).json(response);
});
const quoteTable = new cloud.Table("quotes");
// quote-add [name] [value]
endpoint.post("/quote-add", async (req, res) => {
const data = parseUrlEncodedBody(req.body);
const kvp = getIdValue(data.text);
if (!kvp) {
res.status(400).end();
return;
}
console.log(`Saving '${kvp.key}'='${kvp.value}'`);
// Fetch the array.
const value = await quoteTable.get({ id: kvp.key });
const array: string[] = (value && value.array) || [];
const cloud = require("@pulumi/cloud-aws");
// Create a mapping from 'route' to a count
let counterTable = new cloud.Table("counterTable", "route");
// Create an API endpoint
let endpoint = new cloud.API("hello-world");
endpoint.get("/{route+}", (req, res) => {
let route = req.params["route"];
console.log(`Getting count for '${route}'`);
// get previous value and increment
// reference outer `counterTable` object
counterTable.get({ route }).then(value => {
let count = (value && value.count) || 0;
counterTable.insert({ route, count: ++count }).then(() => {
res.status(200).json({ route, count });
console.log(`Got count ${count} for '${route}'`);
});
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
// Note: @pulumi/cloud is a preview package demonstrating how to create cross-cloud Pulumi
// components. If you are targeting a specific cloud like AWS, Azure, or GCP, we recommend you use
// platform-specific packages like @pulumi/aws, @pulumi/azure or @pulumi/gcp. These packages give
// you full access to the breadth of the platform's capabilities and comes with many abstractions to
// make developing against that platform easier.
import * as cloud from "@pulumi/cloud-aws";
// Create a web server.
const endpoint = new cloud.API("urlshortener");
// Create a table `urls`, with `name` as primary key.
const urlTable = new cloud.Table("urls", "name");
// Serve all files in the www directory to the root.
endpoint.static("/", "www");
// GET /url lists all URLs currently registered.
endpoint.get("/url", async (req, res) => {
try {
const items = await urlTable.scan();
res.status(200).json(items);
console.log(`GET /url retrieved ${items.length} items`);
} catch (err) {
res.status(500).json(err.stack);
console.log(`GET /url error: ${err.stack}`);
}
});
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
"use strict";
const cloud = require("@pulumi/cloud-aws");
const video = require("./video-label-processor");
// A bucket to store videos and thumbnails.
const bucket = new cloud.Bucket("bucket");
const bucketName = bucket.bucket.id;
// A task which runs a containerized FFMPEG job to extract a thumbnail image.
const ffmpegThumbnailTask = new cloud.Task("ffmpegThumbTask", {
build: "./docker-ffmpeg-thumb",
memoryReservation: 512,
});
// Use module for processing video through Rekognition
const videoProcessor = new video.VideoLabelProcessor();
// When a new video is uploaded, start Rekognition label detection
bucket.onPut("onNewVideo", bucketArgs => {
console.log(`*** New video: file ${bucketArgs.key} was uploaded at ${bucketArgs.eventTime}.`);
videoProcessor.startRekognitionJob(bucketName.get(), bucketArgs.key);
return Promise.resolve();
}, { keySuffix: ".mp4" }); // run this Lambda only on .mp4 files
// When Rekognition processing is complete, run the FFMPEG task on the video file
// Use the timestamp with the highest confidence for the label "cat"
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
const cloud = require("@pulumi/cloud-aws");
// A bucket to store videos and thumbnails.
const bucket = new cloud.Bucket("bucket");
const bucketName = bucket.bucket.id;
// A task which runs a containerized FFMPEG job to extract a thumbnail image.
const ffmpegThumbnailTask = new cloud.Task("ffmpegThumbTask", {
build: "./docker-ffmpeg-thumb",
memoryReservation: 512,
});
// When a new video is uploaded, run the FFMPEG task on the video file.
// Use the time index specified in the filename (e.g. cat_00-01.mp4 uses timestamp 00:01)
bucket.onPut("onNewVideo", bucketArgs => {
console.log(`*** New video: file ${bucketArgs.key} was uploaded at ${bucketArgs.eventTime}.`);
const file = bucketArgs.key;
const thumbnailFile = file.substring(0, file.indexOf('_')) + '.jpg';
const framePos = file.substring(file.indexOf('_')+1, file.indexOf('.')).replace('-',':');
ffmpegThumbnailTask.run({
environment: {
"S3_BUCKET": bucketName.get(),
interface SlackSlashCommandResponse {
response_type?: SlackSlashCommandResponseType;
text: string;
attachments?: SlackSlashCommandResponseAttachment[];
}
interface SlackSlashCommandResponseAttachment {
text: string;
}
// Create an API endpoint
let endpoint = new cloud.HttpEndpoint("echo");
endpoint.get("/test", async (req, res) => {
const now = Date.now();
console.log(now);
res.status(200).end(now.toString());
});
endpoint.post("/echo", async (req, res) => {
const data = parseUrlEncodedBody(req.body);
const response: SlackSlashCommandResponse = {
response_type: "in_channel",
text: data.text,
};
res.status(200).json(response);