|
| 1 | +import { resolve } from 'node:path'; |
| 2 | +import * as aws from '@pulumi/aws'; |
| 3 | +import * as pulumi from '@pulumi/pulumi'; |
| 4 | +import { Environment } from './environment'; |
| 5 | +import { S3 } from './s3'; |
| 6 | + |
| 7 | +export function deployAWSArtifactsLambdaFunction(args: { |
| 8 | + environment: Environment; |
| 9 | + /** Note: We run this mirror only on the AWS S3 Bucket on purpose. */ |
| 10 | + s3Mirror: S3; |
| 11 | +}) { |
| 12 | + const lambdaRole = new aws.iam.Role('lambdaRole', { |
| 13 | + assumeRolePolicy: { |
| 14 | + Version: '2012-10-17', |
| 15 | + Statement: [ |
| 16 | + { |
| 17 | + Effect: 'Allow', |
| 18 | + Principal: { Service: 'lambda.amazonaws.com' }, |
| 19 | + Action: 'sts:AssumeRole', |
| 20 | + }, |
| 21 | + ], |
| 22 | + }, |
| 23 | + }); |
| 24 | + |
| 25 | + const awsLambdaArtifactsHandler = new aws.lambda.Function('awsLambdaArtifactsHandler', { |
| 26 | + name: `hive-artifacts-handler-${args.environment.envName}`, |
| 27 | + runtime: aws.lambda.Runtime.NodeJS22dX, |
| 28 | + handler: 'index.worker.mjs', |
| 29 | + architectures: ['arm64'], |
| 30 | + code: new pulumi.asset.AssetArchive({ |
| 31 | + 'index.worker.mjs': |
| 32 | + process.env.AWS_LAMBDA_ARTIFACT_PATH || |
| 33 | + resolve(__dirname, '../../packages/services/cdn-worker/dist/index.worker.mjs'), |
| 34 | + }), |
| 35 | + role: lambdaRole.arn, |
| 36 | + region: 'us-east-2', |
| 37 | + environment: { |
| 38 | + variables: { |
| 39 | + // yeah this is illegal but I frist need to figure out how to use secret store or some stuff |
| 40 | + AWS_S3_ENDPOINT: args.s3Mirror.secret.raw.endpoint, |
| 41 | + AWS_S3_BUCKET_NAME: args.s3Mirror.secret.raw.bucket, |
| 42 | + AWS_S3_ACCESS_KEY_ID: args.s3Mirror.secret.raw.accessKeyId, |
| 43 | + AWS_S3_ACCESSS_KEY_SECRET: args.s3Mirror.secret.raw.secretAccessKey, |
| 44 | + }, |
| 45 | + }, |
| 46 | + // 448mb |
| 47 | + memorySize: 448, |
| 48 | + // 10 seconds |
| 49 | + timeout: 10, |
| 50 | + }); |
| 51 | + |
| 52 | + const example = new aws.lambda.FunctionUrl('example', { |
| 53 | + functionName: awsLambdaArtifactsHandler.name, |
| 54 | + qualifier: args.environment.envVars.RELEASE, |
| 55 | + authorizationType: 'NONE', |
| 56 | + invokeMode: 'BUFFERED', |
| 57 | + }); |
| 58 | + |
| 59 | + return { |
| 60 | + functionUrl: example.functionUrl, |
| 61 | + }; |
| 62 | +} |
0 commit comments