Skip to content

Commit

Permalink
Revert aws-ts-thumbnailer, aws-ts-pulumi-webhooks, aws-ts-thumbnailer…
Browse files Browse the repository at this point in the history
… to aws v5

Not 100% clear yet how to port them correctly.

Also, fix container creation in aws-ts-thumbnailer.
  • Loading branch information
thomas11 committed Oct 23, 2023
1 parent cf12e76 commit 44b0e29
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 42 deletions.
48 changes: 20 additions & 28 deletions aws-ts-lambda-efs/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as aws from "@pulumi/aws";
import * as apigateway from "@pulumi/aws-apigateway";
import * as awsx from "@pulumi/awsx";
import * as cp from "child_process";
import * as fs from "fs";

export = async () => {

// VPC
const vpc = new awsx.ec2.Vpc("vpc", {}); // subnets default to one private, one public
const vpc = new awsx.ec2.Vpc("vpc", { subnets: [{ type: "private" }, { type: "public" }] });
const subnetIds = await vpc.publicSubnetIds;

// EFS
const filesystem = new aws.efs.FileSystem("filesystem");
const targets: aws.efs.MountTarget[] = [];
vpc.publicSubnetIds.apply(ids => {
for (let i = 0; i < ids.length; i++) {
targets.push(new aws.efs.MountTarget(`fs-mount-${i}`, {
fileSystemId: filesystem.id,
subnetId: ids[i],
securityGroups: [vpc.vpc.defaultSecurityGroupId],
}));
}
});
const targets = [];
for (let i = 0; i < subnetIds.length; i++) {
targets.push(new aws.efs.MountTarget(`fs-mount-${i}`, {
fileSystemId: filesystem.id,
subnetId: subnetIds[i],
securityGroups: [vpc.vpc.defaultSecurityGroupId],
}));
}
const ap = new aws.efs.AccessPoint("ap", {
fileSystemId: filesystem.id,
posixUser: { uid: 1000, gid: 1000 },
rootDirectory: { path: "/www", creationInfo: { ownerGid: 1000, ownerUid: 1000, permissions: "755" } },
}, { dependsOn: targets });

// Lambda
function efsvpcCallback(name: string, f: aws.lambda.Callback<unknown, {statusCode: number, body: string}>) {
function efsvpcCallback(name: string, f: aws.lambda.Callback<awsx.apigateway.Request, awsx.apigateway.Response>) {
return new aws.lambda.CallbackFunction(name, {
policies: [aws.iam.ManagedPolicy.AWSLambdaVPCAccessExecutionRole, aws.iam.ManagedPolicy.LambdaFullAccess],
vpcConfig: {
Expand All @@ -43,13 +41,12 @@ export = async () => {
}

// API Gateway
const api = new apigateway.RestAPI("api", {
const api = new awsx.apigateway.API("api", {
routes: [
{
method: "GET", path: "/files/{filename+}", eventHandler: efsvpcCallback("getHandler", async (ev, ctx) => {
try {
const event = <any>ev;
const f = "/mnt/storage/" + event.pathParameters!.filename;
const f = "/mnt/storage/" + ev.pathParameters!.filename;
const data = fs.readFileSync(f);
return {
statusCode: 200,
Expand All @@ -63,9 +60,8 @@ export = async () => {
{
method: "POST", path: "/files/{filename+}", eventHandler: efsvpcCallback("uploadHandler", async (ev, ctx) => {
try {
const event = <any>ev;
const f = "/mnt/storage/" + event.pathParameters!.filename;
const data = Buffer.from(event.body!, "base64");
const f = "/mnt/storage/" + ev.pathParameters!.filename;
const data = new Buffer(ev.body!, "base64");
fs.writeFileSync(f, data);
return {
statusCode: 200,
Expand All @@ -78,8 +74,7 @@ export = async () => {
},
{
method: "POST", path: "/", eventHandler: efsvpcCallback("execHandler", async (ev, ctx) => {
const event = <any>ev;
const cmd = Buffer.from(event.body!, "base64").toString();
const cmd = new Buffer(ev.body!, "base64").toString();
const buf = cp.execSync(cmd);
return {
statusCode: 200,
Expand All @@ -91,7 +86,7 @@ export = async () => {
});

// ECS Cluster
const cluster = new aws.ecs.Cluster("cluster");
const cluster = new awsx.ecs.Cluster("cluster", { vpc: vpc });
const efsVolumeConfiguration: aws.types.input.ecs.TaskDefinitionVolumeEfsVolumeConfiguration = {
fileSystemId: filesystem.id,
authorizationConfig: { accessPointId: ap.id },
Expand All @@ -101,21 +96,18 @@ export = async () => {

// Fargate Service
const nginx = new awsx.ecs.FargateService("nginx", {
cluster: cluster.arn,
cluster: cluster,
taskDefinitionArgs: {
container: {
name: "nginx",
image: "nginx",
memory: 128,
portMappings: [{ containerPort: 80, hostPort: 80, protocol: "tcp" }],
mountPoints: [{ containerPath: "/usr/share/nginx/html", sourceVolume: "efs" }],
},
volumes: [{ name: "efs", efsVolumeConfiguration }],
},
networkConfiguration: {
subnets: vpc.publicSubnetIds,
securityGroups: [vpc.vpc.defaultSecurityGroupId],
},
securityGroups: [vpc.vpc.defaultSecurityGroupId, ...cluster.securityGroups],
subnets: vpc.publicSubnetIds,
platformVersion: "1.4.0",
});

Expand Down
8 changes: 2 additions & 6 deletions aws-ts-lambda-efs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
"name": "aws-ts-lambda-efs",
"version": "0.1.0",
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-apigateway": "1.1.0-alpha.3",
"@pulumi/awsx": "2.0.0-beta.3",
"@pulumi/aws": "^5.0.0",
"@pulumi/awsx": "^0.40.0",
"@pulumi/pulumi": "^3.0.0"
},
"devDependencies": {
"typescript": "^4.6.2"
}
}
7 changes: 3 additions & 4 deletions aws-ts-pulumi-webhooks/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"name": "typescript",
"devDependencies": {
"@types/node": "^18.0.0",
"typescript": "^4.6.2"
"@types/node": "^8.0.0"
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/awsx": "2.0.0-beta.3",
"@pulumi/aws": "^5.0.0",
"@pulumi/awsx": "^0.40.0",
"@pulumi/pulumi": "^3.0.0",
"@slack/webhook": "^5.0.3"
}
Expand Down
4 changes: 2 additions & 2 deletions aws-ts-thumbnailer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const bucket = new aws.s3.Bucket("bucket");
// Export the bucket name.
export const bucketName = bucket.id;

// Create a repository for the FFMPEG image.
// Create a repository for hte FFMPEG image.
const repo = new awsx.ecr.Repository("repo", {
forceDelete: true,
});

// A task which runs a containerized FFMPEG job to extract a thumbnail image.
const ffmpegThumbnailTask = new awsx.classic.ecs.FargateTaskDefinition("ffmpegThumbTask", {
container: {
image: new awsx.ecr.Image("ffmpegThumbTask", { repositoryUrl: repo.url, context: "./docker-ffmpeg-thumb" }).imageUri,
image: new awsx.ecr.Image("ffmpegThumbTask", { repositoryUrl: repo.url, path: "./docker-ffmpeg-thumb" }).imageUri,
memoryReservation: 512,
},
});
Expand Down
4 changes: 2 additions & 2 deletions aws-ts-thumbnailer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.1.0",
"main": "index.ts",
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/awsx": "2.0.0-beta.3",
"@pulumi/aws": "^5.30.0",
"@pulumi/awsx": "^1.0.2",
"@pulumi/pulumi": "^3.55.0"
}
}

0 comments on commit 44b0e29

Please sign in to comment.