Skip to content

Commit

Permalink
Fix CDK stack
Browse files Browse the repository at this point in the history
  • Loading branch information
Masayoshi Mizutani committed Dec 17, 2020
1 parent 3d51a53 commit f188b25
Show file tree
Hide file tree
Showing 7 changed files with 830 additions and 1,676 deletions.
3 changes: 3 additions & 0 deletions bin/uguisu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
import "source-map-support/register";
import * as cdk from "@aws-cdk/core";
import { UguisuStack } from "../lib/uguisu-stack";
import * as path from 'path';

const app = new cdk.App();
new UguisuStack(app, process.env.UGUISU_STACK_NAME!, {
lambdaBuildPath: path.resolve('.'),
lambdaPackagePath: './lambda/tracker',
snsTopicARN: process.env.UGUISU_SNS_TOPIC!,
lambdaRoleARN: process.env.UGUISU_LAMBDA_ROLE,
s3BucketName: process.env.UGUISU_S3_BUCKET_NAME,
Expand Down
7 changes: 7 additions & 0 deletions lambda/tracker/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/m-mizutani/uguisu"

func main() {
uguisu.New().Start()
}
45 changes: 30 additions & 15 deletions lib/uguisu-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import * as iam from "@aws-cdk/aws-iam";
import * as s3 from "@aws-cdk/aws-s3";
import { SqsEventSource } from "@aws-cdk/aws-lambda-event-sources";
import { SqsSubscription } from "@aws-cdk/aws-sns-subscriptions";
import {
NodejsFunction,
NodejsFunctionProps,
} from "@aws-cdk/aws-lambda-nodejs";
import * as path from "path";

export interface Arguments {
lambdaBuildPath: string;
lambdaPackagePath: string;
snsTopicARN: string;
lambdaRoleARN?: string;
s3BucketName?: string;
Expand Down Expand Up @@ -46,29 +44,46 @@ export class UguisuStack extends cdk.Stack {
const topic = sns.Topic.fromTopicArn(this, "s3Event", args.snsTopicARN);
topic.addSubscription(new SqsSubscription(this.s3EventQueue));

const role = args.lambdaRoleARN
? iam.Role.fromRoleArn(this, "Lambda", args.lambdaRoleARN, {
const lambdaRole = args.lambdaRoleARN
? iam.Role.fromRoleArn(this, "LambdaRole", args.lambdaRoleARN, {
mutable: false,
})
: undefined;

const prop: NodejsFunctionProps = {
entry: path.join(__dirname, "lambda/tracker.js"),
handler: "main",
// const buildPath = path.resolve(__dirname, '../build');
const assertPath = lambda.Code.fromAsset(args.lambdaBuildPath, {
bundling: {
image: lambda.Runtime.GO_1_X.bundlingDockerImage,
user: 'root',
// command: ['find'],

command: [
'bash',
'-c',
'GOOS=linux GOARCH=amd64 go build -o /asset-output/tracker ' + args.lambdaPackagePath,
],

},
exclude: ["node_modules", '*/node_modules'],
});

new lambda.Function(this, 'tracker', {
runtime: lambda.Runtime.GO_1_X,
handler: 'tracker',
code: assertPath,
role: lambdaRole,
timeout: cdk.Duration.seconds(300),
memorySize: 1024,
role: role,
events: [new SqsEventSource(this.s3EventQueue, { batchSize: 1 })],
environment: {
SLACK_WEBHOOK_RUL: args.slackWebhookURL,
SENTRY_DSN: args.sentryDSN || "",
DISABLE_RULES: args.disableRules || "",
},
};

this.tracker = new NodejsFunction(this, "tracker", prop);
events: [new SqsEventSource(this.s3EventQueue, { batchSize: 10 })],
reservedConcurrentExecutions: 1,
});

if (!role && args.s3BucketName) {
if (!lambdaRole && args.s3BucketName) {
const bucket = s3.Bucket.fromBucketAttributes(this, "ImportedBucket", {
bucketArn: "arn:aws:s3:::" + args.s3BucketName,
});
Expand Down
Loading

0 comments on commit f188b25

Please sign in to comment.