Skip to content

Commit

Permalink
Merge pull request #4 from ASCS-eV/feat/add_db_to_deployment
Browse files Browse the repository at this point in the history
feat(ascs.digital): add rds db to deployment
  • Loading branch information
royscheeren authored Jan 4, 2024
2 parents bc2fb69 + 0a4aad4 commit 17b2b83
Show file tree
Hide file tree
Showing 6 changed files with 523 additions and 1,988 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nx/typescript"],
"rules": {}
"rules": {
"@typescript-eslint/no-explicit-any": "off"
}
},
{
"files": ["*.js", "*.jsx"],
Expand Down
2 changes: 1 addition & 1 deletion apps/envited.ascs.digital/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"files": ["*.*"],
"rules": {
"@next/next/no-html-link-for-pages": "off"
"@next/next/no-html-link-for-pages": "warn"
}
},
{
Expand Down
10 changes: 9 additions & 1 deletion apps/envited.ascs.digital/app/api/hello/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
export async function GET(request: Request) {
return new Response('Hello, from API!')

try {
return Response.json('hello dynamic world')
} catch (error) {
console.log('error', error)
return Response.json(error)
}
}

export const dynamic = 'force-dynamic'
56 changes: 54 additions & 2 deletions apps/envited.ascs.digital/stacks/Envited.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,65 @@

import { aws_ec2, aws_rds } from 'aws-cdk-lib'
import { RetentionDays } from 'aws-cdk-lib/aws-logs'
import * as cdk from 'aws-cdk-lib/core'
import { NextjsSite, StackContext } from 'sst/constructs'

export default function Envited({ stack }: StackContext) {

const vpc = new aws_ec2.Vpc(stack, 'Vpc')

const sg = new aws_ec2.SecurityGroup(stack, 'PostgresSG', {
vpc,
description: 'Postgres SG',
allowAllOutbound: true,
})
sg.addIngressRule(aws_ec2.Peer.anyIpv4(), aws_ec2.Port.tcp(5432))

const rdsCluster = new aws_rds.DatabaseCluster(stack, 'Envited', {
engine: aws_rds.DatabaseClusterEngine.auroraPostgres({
version: aws_rds.AuroraPostgresEngineVersion.VER_15_3,
}),
instances: 1,
instanceProps: {
vpc,
securityGroups: [sg],
instanceType: 'serverless' as any,
},
defaultDatabaseName: 'envited',
})

;(rdsCluster.node.findChild('Resource') as aws_rds.CfnDBCluster).serverlessV2ScalingConfiguration = {
minCapacity: 0.5,
maxCapacity: 8,
}
new cdk.CfnOutput(stack, `VpcId${stack.stage}`, {
value: vpc.vpcId,
exportName: `VpcId:${stack.stage}`,
})
new cdk.CfnOutput(stack, `SecretArn${stack.stage}`, {
value: rdsCluster.secret?.secretArn || '',
exportName: `SecretArn:${stack.stage}`,
})

// Create the Next.js site
const site = new NextjsSite(stack, 'envited_ascs_digital', {
path: './',
memorySize: '1024 MB',
timeout: '20 seconds',
environment: {},
edge: false,
cdk: {
server: {
vpc,
logRetention: RetentionDays.ONE_WEEK,
},
revalidation: {
vpc,
},
},
permissions: ['secretsmanager:GetSecretValue'],
environment: {
RDS_SECRET_ARN: rdsCluster.secret?.secretArn || '',
REGION: process.env.region || 'eu-central-1',
},
})

const metadata = site.getConstructMetadata()
Expand Down
Loading

0 comments on commit 17b2b83

Please sign in to comment.