Skip to content

Commit

Permalink
fix: update roles
Browse files Browse the repository at this point in the history
  • Loading branch information
apalchys committed Nov 27, 2023
1 parent 394eb50 commit 300d37d
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions src/cdk/AngularCourseStack.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as cdk from "aws-cdk-lib";
import * as iam from "aws-cdk-lib/aws-iam";
import * as route53 from "aws-cdk-lib/aws-route53";
import * as alias from "aws-cdk-lib/aws-route53-targets";
import * as apiv2 from "@aws-cdk/aws-apigatewayv2-alpha";
import * as integration from "@aws-cdk/aws-apigatewayv2-integrations-alpha";

import * as cloudfront from "aws-cdk-lib/aws-cloudfront";
import { Construct } from "constructs";
import { CfnOutput } from "aws-cdk-lib";
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
import { Runtime } from "aws-cdk-lib/aws-lambda";
import { HttpMethod } from "@aws-cdk/aws-apigatewayv2-alpha";
Expand Down Expand Up @@ -118,19 +118,41 @@ export class AngularCourseStack extends cdk.Stack {

const httpApi = new apiv2.HttpApi(this, "AngularTask");

const lambdaRole = new iam.Role(this, `AngularTaskLambdaRole`, {
assumedBy: new iam.ServicePrincipal("lambda.amazonaws.com"),
inlinePolicies: {
lambdaRole: new iam.PolicyDocument({
statements: [
new iam.PolicyStatement({
actions: ["dynamodb:*"],
resources: [
`arn:aws:dynamodb:${this.region}:${this.account}:table/rsschool-*`,
],
}),
],
}),
},
});

for (const route of angularTaskApi) {
const lambda = new NodejsFunction(
this,
`AngularTask-${route.lambdaName}`,
{
entry: `./src/functions/${route.lambdaName}.ts`,
memorySize: 256,
runtime: Runtime.NODEJS_20_X,
bundling: {
externalModules: ["@aws-sdk/*"],
},
role: lambdaRole,
}
);
new apiv2.HttpRoute(this, `Route-${route.path}-${route.method}`, {
httpApi,
integration: new integration.HttpLambdaIntegration(
`Integration-${route.path}-${route.method}`,
new NodejsFunction(this, `AngularTask-${route.lambdaName}`, {
entry: `./src/functions/${route.lambdaName}.ts`,
memorySize: 256,
runtime: Runtime.NODEJS_20_X,
bundling: {
externalModules: ["@aws-sdk/*"],
},
})
lambda
),
routeKey: apiv2.HttpRouteKey.with(
`${baseUrl}${route.path}`,
Expand Down Expand Up @@ -196,6 +218,6 @@ export class AngularCourseStack extends cdk.Stack {
recordName: this.fqdn,
});

new CfnOutput(this, "API Url", { value: `${this.url}${baseUrl}` });
new cdk.CfnOutput(this, "API Url", { value: `${this.url}${baseUrl}` });
}
}

0 comments on commit 300d37d

Please sign in to comment.