Skip to content

Commit

Permalink
WIP commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AWare committed Oct 30, 2019
1 parent 418e730 commit a36c3c7
Show file tree
Hide file tree
Showing 9 changed files with 775 additions and 869 deletions.
2 changes: 1 addition & 1 deletion projects/archiver/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require('dotenv').config()
export { handler as invoke } from './src/invoke'
export { handler as issue } from './src/tasks/issue'
export { handler as front } from './src/tasks/front'
export { handler as image } from './src/tasks/image'
export { handler as image } from './src/tasks/frontAndImage'
export { handler as upload } from './src/tasks/upload'
export { handler as zip } from './src/tasks/zip'
export { handler as indexer } from './src/tasks/indexer'
Expand Down
55 changes: 0 additions & 55 deletions projects/archiver/src/tasks/front/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ export const handler: Handler<

console.log(`succesfully download front ${frontId}`, maybeFront)


const frontUpload = await attempt(
upload(
frontPath(publishedId, frontId),
maybeFront,
'application/json',
ONE_WEEK,
),
)

if (hasFailed(frontUpload)) {
console.error(JSON.stringify(frontUpload))
throw new Error('Could not upload front')
}
const publishedFronts = [...issue.fronts, frontId]

console.log(`front uploaded`, publishedFronts)






const images: Image[] = unnest(getImagesFromFront(maybeFront))

const imagesWithSizes: [Image, ImageSize][] = unnest(
Expand Down
2 changes: 1 addition & 1 deletion projects/archiver/src/tasks/upload/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Handler } from 'aws-lambda'
import { attempt, hasFailed } from '../../../../backend/utils/try'
import { issuePath } from '../../../common'
import { ImageTaskOutput } from '../image'
import { ImageTaskOutput } from '../frontAndImage'
import { IssueTaskOutput } from '../issue'
import { upload, ONE_WEEK } from '../../utils/s3'
import { handleAndNotify } from '../../services/task-handler'
Expand Down
106 changes: 106 additions & 0 deletions projects/aws/lib/constructs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import * as cdk from '@aws-cdk/core'
import * as lambda from '@aws-cdk/aws-lambda'
import { Code, FunctionProps } from '@aws-cdk/aws-lambda'
import { Duration, Tag } from '@aws-cdk/core'
import { toTitleCase } from './tools'
import * as s3 from '@aws-cdk/aws-s3'
import * as iam from '@aws-cdk/aws-iam'
import * as sfn from '@aws-cdk/aws-stepfunctions'
import * as tasks from '@aws-cdk/aws-stepfunctions-tasks'

export interface StepFunctionProps {
stack: string
stage: string
deployBucket: s3.IBucket
outputBucket: s3.IBucket
backendURL: string
frontsTopicArn: string
frontsTopicRoleArn: string
guNotifyServiceApiKey: string
}
export interface LambdaParams {
stack: string
stage: string
deployBucket: s3.IBucket
outputBucket: s3.IBucket
frontsTopicArn: string
frontsTopicRole: iam.IRole
}

export const taskLambda = (
scope: cdk.Construct,
name: string,
{
stack,
stage,
deployBucket,
outputBucket,
frontsTopicArn,
frontsTopicRole,
}: LambdaParams,
environment?: { [key: string]: string },
overrides?: Partial<FunctionProps>,
) => {
const fn = new lambda.Function(
scope,
`EditionsArchiver${toTitleCase(name)}`,
{
functionName: `editions-archiver-stepmachine-${name}-${stage}`,
runtime: lambda.Runtime.NODEJS_10_X,
timeout: Duration.minutes(5),
memorySize: 1500,
code: Code.bucket(
deployBucket,
`${stack}/${stage}/archiver/archiver.zip`,
),
handler: `index.${name}`,
environment: {
...environment,
stage: stage,
bucket: outputBucket.bucketName,
topic: frontsTopicArn,
role: frontsTopicRole.roleArn,
},
initialPolicy: [
new iam.PolicyStatement({
actions: ['*'],
resources: [
outputBucket.arnForObjects('*'),
outputBucket.bucketArn,
],
}),
new iam.PolicyStatement({
actions: ['sts:AssumeRole'],
resources: [frontsTopicRole.roleArn],
}),
],
...overrides,
},
)
Tag.add(fn, 'App', `editions-archiver-${name}`)
Tag.add(fn, 'Stage', stage)
Tag.add(fn, 'Stack', stack)
return fn
}

export const task = (
scope: cdk.Construct,
name: string,
desc: string,
lambdaParams: LambdaParams,
environment?: { [key: string]: string },
overrides?: Partial<FunctionProps>,
) => {
const lambda = taskLambda(
scope,
'front',
lambdaParams,
environment,
overrides,
)

const task = new sfn.Task(scope, [name, desc].join(': '), {
task: new tasks.InvokeFunction(lambda),
})
return { lambda, task }
}
Loading

0 comments on commit a36c3c7

Please sign in to comment.