1- import type { CdkCustomResourceHandler } from 'aws-lambda' ;
1+ import { ACMClient , ImportCertificateCommand } from '@aws-sdk/client-acm' ;
2+ import type { CdkCustomResourceEvent , CdkCustomResourceHandler } from 'aws-lambda' ;
23import type { pki } from 'node-forge' ;
34import { generate } from 'selfsigned' ;
4- import { ACMClient , ImportCertificateCommand } from '@aws-sdk/client-acm' ;
55
66const acmClient = new ACMClient ( { } ) ;
77
8+ export type CustomResourceProps = {
9+ certificateDetails : { commonName : string ; [ key : string ] : string } ;
10+ tags ?: { key : string ; value : string } [ ] ;
11+ } ;
12+
13+ type ResourceProps = CdkCustomResourceEvent [ 'ResourceProperties' ] & CustomResourceProps
14+
815export const handler : CdkCustomResourceHandler = async ( event ) => {
916 if ( event . RequestType == 'Delete' ) {
1017 // TODO: remove from imports?
1118 return { } ;
1219 }
1320
14- const certificateDetails = event . ResourceProperties . certificateDetails ;
21+ const resourceProps = event . ResourceProperties as ResourceProps ;
22+ const certificateDetails = resourceProps . certificateDetails ;
1523 const certFields : pki . CertificateField [ ] = Object . keys ( certificateDetails ) . map ( key => ( {
1624 name : key ,
1725 value : certificateDetails [ key ] ,
@@ -25,7 +33,13 @@ export const handler: CdkCustomResourceHandler = async (event) => {
2533 CertificateArn : event . RequestType == 'Update' ? event . PhysicalResourceId : undefined ,
2634 Certificate : new Uint8Array ( Buffer . from ( generatedCertificate . cert , 'utf-8' ) ) ,
2735 PrivateKey : new Uint8Array ( Buffer . from ( generatedCertificate . private , 'utf-8' ) ) ,
28- Tags : event . ResourceProperties . tags ,
36+ Tags : resourceProps . tags ?. map ( ( {
37+ key,
38+ value,
39+ } ) => ( {
40+ Key : key ,
41+ Value : value ,
42+ } ) ) ,
2943 } ) ) ;
3044
3145 console . log ( 'Import result' , importResult . CertificateArn ) ;
0 commit comments