aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 2.43 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0}),exports.NotificationsResourceHandler=exports.NotificationsResourceHandlerProps=void 0;var fs=()=>{var tmp=require("fs");return fs=()=>tmp,tmp},path=()=>{var tmp=require("path");return path=()=>tmp,tmp},constructs_1=()=>{var tmp=require("constructs");return constructs_1=()=>tmp,tmp},iam=()=>{var tmp=require("../../../aws-iam");return iam=()=>tmp,tmp},cdk=()=>{var tmp=require("../../../core");return cdk=()=>tmp,tmp};class NotificationsResourceHandlerProps{}exports.NotificationsResourceHandlerProps=NotificationsResourceHandlerProps;class NotificationsResourceHandler extends constructs_1().Construct{static singleton(context,props={}){const root=cdk().Stack.of(context),logicalId="BucketNotificationsHandler050a0587b7544547bf325f094a3db834";let lambda=root.node.tryFindChild(logicalId);return lambda||(lambda=new NotificationsResourceHandler(root,logicalId,props)),lambda}constructor(scope,id,props={}){super(scope,id),this.role=props.role??new(iam()).Role(this,"Role",{assumedBy:new(iam()).ServicePrincipal("lambda.amazonaws.com")}),this.role.addManagedPolicy(iam().ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSLambdaBasicExecutionRole")),this.role.addToPrincipalPolicy(new(iam()).PolicyStatement({actions:["s3:PutBucketNotification"],resources:["*"]}));const resourceType="AWS::Lambda::Function";class InLineLambda extends cdk().CfnResource{constructor(){super(...arguments),this.tags=new(cdk()).TagManager(cdk().TagType.STANDARD,resourceType)}renderProperties(properties){return properties.Tags=cdk().listMapper(cdk().cfnTagToCloudFormation)(this.tags.renderTags()),delete properties.tags,properties}}const handlerSourceWithoutComments=fs().readFileSync(path().join(__dirname,"..","..","..","custom-resource-handlers","dist","aws-s3","notifications-resource-handler","index.py"),"utf8").replace(/^ *#.*\n?/gm,""),resource=new InLineLambda(this,"Resource",{type:resourceType,properties:{Description:'AWS CloudFormation handler for "Custom::S3BucketNotifications" resources (@aws-cdk/aws-s3)',Code:{ZipFile:handlerSourceWithoutComments},Handler:"index.handler",Role:this.role.roleArn,Runtime:"python3.11",Timeout:300}});resource.node.addDependency(this.role),this.functionArn=resource.getAtt("Arn").toString()}addToRolePolicy(statement){this.role.addToPrincipalPolicy(statement)}}exports.NotificationsResourceHandler=NotificationsResourceHandler;
;