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IAAI,MAAM,mCAEd,EAAM,kBAAkB,SAAS,WACnC,EAAO,YAAY,EAAe,gBAEhC,EAAM,kBAAkB,SAAS,QACnC,EAAO,SAAS,EAAe,gBAE7B,EAAM,kBAAkB,SAAS,SACnC,EAAO,UAAU,EAAe,gBAE9B,EAAM,kBAAkB,SAAS,cACnC,EAAO,eAAe,EAAe,gBAEnC,EAAM,kBAAkB,SAAS,UACnC,EAAO,WAAW,EAAe,eAErC,EArGF,QAAA,sB","file":"/npm/@aws-solutions-constructs/aws-lambda-s3@2.96.0/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@aws-solutions-constructs/aws-lambda-s3@2.96.0/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n *  Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n *  Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance\n *  with the License. A copy of the License is located at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n *  or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES\n *  OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions\n *  and limitations under the License.\n */\n\n// Imports\nimport * as lambda from 'aws-cdk-lib/aws-lambda';\nimport * as s3 from 'aws-cdk-lib/aws-s3';\nimport * as ec2 from 'aws-cdk-lib/aws-ec2';\nimport * as defaults from '@aws-solutions-constructs/core';\n// Note: To ensure CDKv2 compatibility, keep the import statement for Construct separate\nimport { Construct } from 'constructs';\n\n/**\n * @summary The properties for the LambdaToS3 class.\n */\nexport interface LambdaToS3Props {\n  /**\n   * Existing instance of Lambda Function object, providing both this and `lambdaFunctionProps` will cause an error.\n   *\n   * @default - None\n   */\n  readonly existingLambdaObj?: lambda.Function;\n  /**\n   * Optional user provided props to override the default props for the Lambda function.\n   *\n   * @default - Default properties are used.\n   */\n  readonly lambdaFunctionProps?: lambda.FunctionProps;\n  /**\n   * Existing instance of S3 Bucket object, providing both this and `bucketProps` will cause an error.\n   *\n   * @default - None\n   */\n  readonly existingBucketObj?: s3.IBucket;\n  /**\n   * Optional user provided props to override the default props for the S3 Bucket.\n   *\n   * @default - Default props are used\n   */\n  readonly bucketProps?: s3.BucketProps;\n  /**\n   * Optional bucket permissions to grant to the Lambda function.\n   * One or more of the following may be specified: \"Delete\", \"Put\", \"Read\", \"ReadWrite\", \"Write\".\n   *\n   * @default - Read/write access is given to the Lambda function if no value is specified.\n   */\n  readonly bucketPermissions?: string[];\n  /**\n   * An existing VPC for the construct to use (construct will NOT create a new VPC in this case)\n   */\n  readonly existingVpc?: ec2.IVpc;\n  /**\n   * Properties to override default properties if deployVpc is true\n   */\n  readonly vpcProps?: ec2.VpcProps;\n  /**\n   * Whether to deploy a new VPC\n   *\n   * @default - false\n   */\n  readonly deployVpc?: boolean;\n  /**\n   * Optional Name for the Lambda function environment variable set to the name of the bucket.\n   *\n   * @default - S3_BUCKET_NAME\n   */\n  readonly bucketEnvironmentVariableName?: string;\n  /**\n   * Optional user provided props to override the default props for the S3 Logging Bucket.\n   *\n   * @default - Default props are used\n   */\n  readonly loggingBucketProps?: s3.BucketProps\n  /**\n   * Whether to turn on Access Logs for the S3 bucket with the associated storage costs.\n   * Enabling Access Logging is a best practice.\n   *\n   * @default - true\n   */\n  readonly logS3AccessLogs?: boolean;\n}\n\n/**\n * @summary The LambdaToS3 class.\n */\nexport class LambdaToS3 extends Construct {\n  public readonly lambdaFunction: lambda.Function;\n  public readonly s3Bucket?: s3.Bucket;\n  public readonly s3LoggingBucket?: s3.Bucket;\n  public readonly vpc?: ec2.IVpc;\n  public readonly s3BucketInterface: s3.IBucket;\n\n  /**\n   * @summary Constructs a new instance of the LambdaToS3 class.\n   * @param {cdk.App} scope - represents the scope for all the resources.\n   * @param {string} id - this is a a scope-unique id.\n   * @param {LambdaToS3Props} props - user provided props for the construct.\n   * @since 0.8.0\n   * @access public\n   */\n  constructor(scope: Construct, id: string, props: LambdaToS3Props) {\n    super(scope, id);\n\n    // All our tests are based upon this behavior being on, so we're setting\n    // context here rather than assuming the client will set it\n    this.node.setContext(\"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy\", true);\n\n    defaults.CheckS3Props(props);\n    defaults.CheckVpcProps(props);\n    defaults.CheckLambdaProps(props);\n\n    if (props.bucketPermissions) {\n      defaults.CheckListValues(['Delete', 'Put', 'Read', 'ReadWrite', 'Write'], props.bucketPermissions, 'bucket permission');\n    }\n\n    let bucket: s3.IBucket;\n\n    if (props.deployVpc || props.existingVpc) {\n      this.vpc = defaults.buildVpc(scope, {\n        defaultVpcProps: defaults.DefaultIsolatedVpcProps(),\n        existingVpc: props.existingVpc,\n        userVpcProps: props.vpcProps,\n        constructVpcProps: {\n          enableDnsHostnames: true,\n          enableDnsSupport: true,\n        },\n      });\n\n      defaults.AddAwsServiceEndpoint(scope, this.vpc, defaults.ServiceEndpointTypes.S3);\n    }\n\n    // Setup the Lambda function\n    this.lambdaFunction = defaults.buildLambdaFunction(this, {\n      existingLambdaObj: props.existingLambdaObj,\n      lambdaFunctionProps: props.lambdaFunctionProps,\n      vpc: this.vpc,\n    });\n\n    // Setup S3 Bucket\n    if (!props.existingBucketObj) {\n      const buildS3BucketResponse = defaults.buildS3Bucket(this, {\n        bucketProps: props.bucketProps,\n        loggingBucketProps: props.loggingBucketProps,\n        logS3AccessLogs: props.logS3AccessLogs\n      });\n      this.s3Bucket = buildS3BucketResponse.bucket;\n      this.s3LoggingBucket = buildS3BucketResponse.loggingBucket;\n\n      bucket = this.s3Bucket;\n    } else {\n      bucket = props.existingBucketObj;\n    }\n\n    this.s3BucketInterface = bucket;\n\n    // Configure environment variables\n    const bucketEnvironmentVariableName = props.bucketEnvironmentVariableName || 'S3_BUCKET_NAME';\n    this.lambdaFunction.addEnvironment(bucketEnvironmentVariableName, bucket.bucketName);\n\n    // Add the requested or default bucket permissions\n    if (props.bucketPermissions) {\n      this.AssignAppropriatePrivileges(props, bucket, this.lambdaFunction);\n    } else {\n      bucket.grantReadWrite(this.lambdaFunction.grantPrincipal);\n    }\n  }\n\n  private AssignAppropriatePrivileges(props: LambdaToS3Props, bucket: s3.IBucket, clientFunction: lambda.Function) {\n    if (!props.bucketPermissions) {\n      throw new Error('bucketPermissions required here');\n    }\n    if (props.bucketPermissions.includes('Delete')) {\n      bucket.grantDelete(clientFunction.grantPrincipal);\n    }\n    if (props.bucketPermissions.includes('Put')) {\n      bucket.grantPut(clientFunction.grantPrincipal);\n    }\n    if (props.bucketPermissions.includes('Read')) {\n      bucket.grantRead(clientFunction.grantPrincipal);\n    }\n    if (props.bucketPermissions.includes('ReadWrite')) {\n      bucket.grantReadWrite(clientFunction.grantPrincipal);\n    }\n    if (props.bucketPermissions.includes('Write')) {\n      bucket.grantWrite(clientFunction.grantPrincipal);\n    }\n  }\n}"]}