48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { Construct } from 'constructs';
|
|
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
|
|
import * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
import {
|
|
BasePathMapping,
|
|
IDomainName,
|
|
LambdaIntegration,
|
|
RestApi
|
|
} from 'aws-cdk-lib/aws-apigateway';
|
|
import { Effect, PolicyStatement } from 'aws-cdk-lib/aws-iam';
|
|
|
|
export interface ContactConstructProps {
|
|
apiDomainName: IDomainName;
|
|
}
|
|
|
|
export class ContactConstruct extends Construct {
|
|
constructor(scope: Construct, id: string, props: ContactConstructProps) {
|
|
super(scope, id);
|
|
|
|
const contactServiceRestApi = new RestApi(this, 'ContactService', {
|
|
description: 'The ContactService rest api.'
|
|
});
|
|
new BasePathMapping(this, 'ContactServiceMapping', {
|
|
domainName: props.apiDomainName,
|
|
restApi: contactServiceRestApi,
|
|
basePath: 'contact'
|
|
});
|
|
|
|
// contact endpoint
|
|
const contactLambda = new NodejsFunction(this, 'Contact', {
|
|
description: 'The lambda for the contact endpoint.',
|
|
runtime: lambda.Runtime.NODEJS_24_X
|
|
});
|
|
const contactIntegration = new LambdaIntegration(contactLambda);
|
|
const contactResource =
|
|
contactServiceRestApi.root.addResource('contact');
|
|
contactResource.addMethod('POST', contactIntegration);
|
|
|
|
contactLambda.addToRolePolicy(
|
|
new PolicyStatement({
|
|
actions: ['ses:SendEmail', 'ses:SendRawEmail'],
|
|
effect: Effect.ALLOW,
|
|
resources: ['*']
|
|
})
|
|
);
|
|
}
|
|
}
|