UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 16.2 kB
"use strict";var __runInitializers=exports&&exports.__runInitializers||function(thisArg,initializers,value){for(var useValue=arguments.length>2,i=0;i<initializers.length;i++)value=useValue?initializers[i].call(thisArg,value):initializers[i].call(thisArg);return useValue?value:void 0},__esDecorate=exports&&exports.__esDecorate||function(ctor,descriptorIn,decorators,contextIn,initializers,extraInitializers){function accept(f){if(f!==void 0&&typeof f!="function")throw new TypeError("Function expected");return f}for(var kind=contextIn.kind,key=kind==="getter"?"get":kind==="setter"?"set":"value",target=!descriptorIn&&ctor?contextIn.static?ctor:ctor.prototype:null,descriptor=descriptorIn||(target?Object.getOwnPropertyDescriptor(target,contextIn.name):{}),_,done=!1,i=decorators.length-1;i>=0;i--){var context={};for(var p in contextIn)context[p]=p==="access"?{}:contextIn[p];for(var p in contextIn.access)context.access[p]=contextIn.access[p];context.addInitializer=function(f){if(done)throw new TypeError("Cannot add initializers after decoration has completed");extraInitializers.push(accept(f||null))};var result=(0,decorators[i])(kind==="accessor"?{get:descriptor.get,set:descriptor.set}:descriptor[key],context);if(kind==="accessor"){if(result===void 0)continue;if(result===null||typeof result!="object")throw new TypeError("Object expected");(_=accept(result.get))&&(descriptor.get=_),(_=accept(result.set))&&(descriptor.set=_),(_=accept(result.init))&&initializers.unshift(_)}else(_=accept(result))&&(kind==="field"?initializers.unshift(_):descriptor[key]=_)}target&&Object.defineProperty(target,contextIn.name,descriptor),done=!0};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Memory=exports.MemoryBase=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var perms_1=()=>{var tmp=require("./perms");return perms_1=()=>tmp,tmp},aws_bedrockagentcore_1=()=>{var tmp=require("../../../aws-bedrockagentcore");return aws_bedrockagentcore_1=()=>tmp,tmp},aws_cloudwatch_1=()=>{var tmp=require("../../../aws-cloudwatch");return aws_cloudwatch_1=()=>tmp,tmp},iam=()=>{var tmp=require("../../../aws-iam");return iam=()=>tmp,tmp},kms=()=>{var tmp=require("../../../aws-kms");return kms=()=>tmp,tmp},core_1=()=>{var tmp=require("../../../core");return core_1=()=>tmp,tmp},metadata_resource_1=()=>{var tmp=require("../../../core/lib/metadata-resource");return metadata_resource_1=()=>tmp,tmp},prop_injectable_1=()=>{var tmp=require("../../../core/lib/prop-injectable");return prop_injectable_1=()=>tmp,tmp},validation_helpers_1=()=>{var tmp=require("../common/validation-helpers");return validation_helpers_1=()=>tmp,tmp};const MEMORY_NAME_MIN_LENGTH=1,MEMORY_NAME_MAX_LENGTH=48,MEMORY_TAG_MIN_LENGTH=1,MEMORY_TAG_MAX_LENGTH=256,MEMORY_EXPIRATION_DAYS_MIN=7,MEMORY_EXPIRATION_DAYS_MAX=365;class MemoryBase extends core_1().Resource{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.MemoryBase",version:"2.257.0"};get memoryRef(){return{memoryArn:this.memoryArn}}constructor(scope,id,props={}){super(scope,id,props);try{jsiiDeprecationWarnings().aws_cdk_lib_ResourceProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,MemoryBase),error}}grant(grantee,...actions){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grant),error}return iam().Grant.addToPrincipal({grantee,actions,resourceArns:[this.memoryRef.memoryArn]})}grantWrite(grantee){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantWrite),error}return this.grant(grantee,...perms_1().MemoryPerms.STM.WRITE_PERMS)}grantRead(grantee){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantRead),error}return this.grant(grantee,...perms_1().MemoryPerms.READ_PERMS)}grantReadShortTermMemory(grantee){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantReadShortTermMemory),error}return this.grant(grantee,...perms_1().MemoryPerms.STM.READ_PERMS)}grantReadLongTermMemory(grantee){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantReadLongTermMemory),error}return this.grant(grantee,...perms_1().MemoryPerms.LTM.READ_PERMS)}grantDelete(grantee){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantDelete),error}return this.grant(grantee,...perms_1().MemoryPerms.DELETE_PERMS)}grantDeleteShortTermMemory(grantee){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantDeleteShortTermMemory),error}return this.grant(grantee,...perms_1().MemoryPerms.STM.DELETE_PERMS)}grantDeleteLongTermMemory(grantee){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantDeleteLongTermMemory),error}return this.grant(grantee,...perms_1().MemoryPerms.LTM.DELETE_PERMS)}grantAdmin(grantee){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantAdmin),error}return this.grant(grantee,...perms_1().MemoryPerms.ADMIN_PERMS)}grantFullAccess(grantee){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantFullAccess),error}return this.grant(grantee,...perms_1().MemoryPerms.FULL_ACCESS_PERMS)}metric(metricName,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metric),error}const metricProps={namespace:"AWS/Bedrock-AgentCore",metricName,...props,dimensionsMap:{Resource:this.memoryRef.memoryArn,...props?.dimensionsMap}};return this.configureMetric(metricProps)}metricForApiOperation(metricName,operation,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricForApiOperation),error}return this.metric(metricName,{dimensionsMap:{Operation:operation},...props})}metricLatencyForApiOperation(operation,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricLatencyForApiOperation),error}return this.metricForApiOperation("Latency",operation,{statistic:aws_cloudwatch_1().Stats.AVERAGE,...props})}metricInvocationsForApiOperation(operation,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricInvocationsForApiOperation),error}return this.metricForApiOperation("Invocations",operation,{statistic:aws_cloudwatch_1().Stats.SUM,...props})}metricErrorsForApiOperation(operation,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricErrorsForApiOperation),error}return this.metricForApiOperation("Errors",operation,{statistic:aws_cloudwatch_1().Stats.SUM,...props})}metricEventCreationCount(props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricEventCreationCount),error}return this.metric("CreationCount",{dimensionsMap:{ItemType:"Event"},statistic:aws_cloudwatch_1().Stats.SUM,...props})}metricMemoryRecordCreationCount(props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricMemoryRecordCreationCount),error}return this.metric("CreationCount",{dimensionsMap:{ItemType:"MemoryRecordsExtracted"},statistic:aws_cloudwatch_1().Stats.SUM,...props})}configureMetric(props){return new(aws_cloudwatch_1()).Metric({...props,region:props?.region??this.stack.region,account:props?.account??this.stack.account})}}exports.MemoryBase=MemoryBase;let Memory=(()=>{let _classDecorators=[prop_injectable_1().propertyInjectable],_classDescriptor,_classExtraInitializers=[],_classThis,_classSuper=MemoryBase,_instanceExtraInitializers=[],_addMemoryStrategy_decorators;var Memory2=class extends _classSuper{static{_classThis=this}static{const _metadata=typeof Symbol=="function"&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;_addMemoryStrategy_decorators=[(0,metadata_resource_1().MethodMetadata)()],__esDecorate(this,null,_addMemoryStrategy_decorators,{kind:"method",name:"addMemoryStrategy",static:!1,private:!1,access:{has:obj=>"addMemoryStrategy"in obj,get:obj=>obj.addMemoryStrategy},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(null,_classDescriptor={value:_classThis},_classDecorators,{kind:"class",name:_classThis.name,metadata:_metadata},null,_classExtraInitializers),Memory2=_classThis=_classDescriptor.value,_metadata&&Object.defineProperty(_classThis,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:_metadata})}static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.Memory",version:"2.257.0"};static PROPERTY_INJECTION_ID="aws-cdk-lib.aws-bedrockagentcore.Memory";static fromMemoryAttributes(scope,id,attrs){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_MemoryAttributes(attrs)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromMemoryAttributes),error}class Import extends MemoryBase{memoryArn=attrs.memoryArn;memoryId=core_1().Arn.split(attrs.memoryArn,core_1().ArnFormat.SLASH_RESOURCE_NAME).resourceName;executionRole=iam().Role.fromRoleArn(scope,`${id}Role`,attrs.roleArn);kmsKey=attrs.kmsKeyArn?kms().Key.fromKeyArn(scope,`${id}Key`,attrs.kmsKeyArn):void 0;updatedAt=attrs.updatedAt;grantPrincipal=this.executionRole;status=attrs.status;createdAt=attrs.createdAt;constructor(s,i){super(s,i),this.grantPrincipal=this.executionRole||new(iam()).UnknownPrincipal({resource:this})}}return new Import(scope,id)}memoryArn=__runInitializers(this,_instanceExtraInitializers);memoryName;memoryId;expirationDuration;failureReason;description;executionRole;status;createdAt;updatedAt;tags;grantPrincipal;kmsKey;memoryStrategies=[];__resource;constructor(scope,id,props={}){super(scope,id,{physicalName:props?.memoryName??core_1().Lazy.string({produce:()=>core_1().Names.uniqueResourceName(this,{maxLength:48})})});try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_MemoryProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,Memory2),error}(0,metadata_resource_1().addConstructMetadata)(this,props),this.memoryName=this.physicalName,this.expirationDuration=props.expirationDuration??core_1().Duration.days(90),this.description=props.description,this.kmsKey=props.kmsKey,this.executionRole=props.executionRole??this._createMemoryRole(),this.grantPrincipal=this.executionRole,this.tags=props.tags,this.kmsKey&&this.kmsKey.grant(this.executionRole,"kms:CreateGrant","kms:Decrypt","kms:DescribeKey","kms:GenerateDataKey","kms:GenerateDataKeyWithoutPlaintext","kms:ReEncrypt*"),(0,validation_helpers_1().throwIfInvalid)(this._validateMemoryName,this.memoryName,this),(0,validation_helpers_1().throwIfInvalid)(this._validateMemoryExpirationDays,this.expirationDuration.toDays()),(0,validation_helpers_1().throwIfInvalid)(this._validateMemoryTags,this.tags,this);const cfnProps={name:this.memoryName,description:this.description,eventExpiryDuration:this.expirationDuration.toDays(),encryptionKeyArn:this.kmsKey?.keyArn,memoryExecutionRoleArn:this.executionRole?.roleArn,memoryStrategies:core_1().Lazy.any({produce:()=>this._renderMemoryStrategies()},{omitEmptyArray:!0}),tags:this.tags};this.__resource=new(aws_bedrockagentcore_1()).CfnMemory(this,"Memory",cfnProps),this.memoryId=this.__resource.attrMemoryId,this.memoryArn=this.__resource.attrMemoryArn,this.status=this.__resource.attrStatus,this.updatedAt=this.__resource.attrUpdatedAt,this.createdAt=this.__resource.attrCreatedAt,this.failureReason=this.__resource.attrFailureReason;for(const strategy of props?.memoryStrategies??[])this.addMemoryStrategy(strategy)}addMemoryStrategy(memoryStrategy){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_IMemoryStrategy(memoryStrategy)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.addMemoryStrategy),error}this.memoryStrategies.push(memoryStrategy),memoryStrategy.grant(this.executionRole)?.applyBefore(this.__resource)}_createMemoryRole(){return new(iam()).Role(this,"ServiceRole",{assumedBy:new(iam()).ServicePrincipal("bedrock-agentcore.amazonaws.com",{conditions:{StringEquals:{"aws:SourceAccount":core_1().Stack.of(this).account},ArnLike:{"aws:SourceArn":core_1().Arn.format({service:"bedrock-agentcore",resource:"memory",resourceName:`${this.memoryName}*`},core_1().Stack.of(this))}}})})}_validateMemoryTags=(tags,scope)=>{let errors=[];if(!tags)return errors;for(const[key,value]of Object.entries(tags)){key.toLowerCase().startsWith("aws:")&&errors.push(`Tag key "${key}" cannot start with "aws:" as this prefix is reserved by AWS`),errors.push(...(0,validation_helpers_1().validateStringFieldLength)({value:key,fieldName:"Tag key",minLength:MEMORY_TAG_MIN_LENGTH,maxLength:MEMORY_TAG_MAX_LENGTH},scope));const validKeyPattern=/^[a-zA-Z0-9\s._:/=+@-]*$/;errors.push(...(0,validation_helpers_1().validateFieldPattern)(key,"Tag key",validKeyPattern,void 0,scope)),errors.push(...(0,validation_helpers_1().validateStringFieldLength)({value,fieldName:"Tag value",minLength:MEMORY_TAG_MIN_LENGTH,maxLength:MEMORY_TAG_MAX_LENGTH},scope));const validValuePattern=/^[a-zA-Z0-9\s._:/=+@-]*$/;errors.push(...(0,validation_helpers_1().validateFieldPattern)(value,"Tag value",validValuePattern,void 0,scope))}return errors};_validateMemoryName=(name,scope)=>{let errors=[];errors.push(...(0,validation_helpers_1().validateStringFieldLength)({value:name,fieldName:"Memory name",minLength:MEMORY_NAME_MIN_LENGTH,maxLength:MEMORY_NAME_MAX_LENGTH},scope));const validNamePattern=/^[a-zA-Z][a-zA-Z0-9_]{0,47}$/;return errors.push(...(0,validation_helpers_1().validateFieldPattern)(name,"Memory name",validNamePattern,void 0,scope)),errors};_validateMemoryExpirationDays=expirationDays=>{let errors=[];return core_1().Token.isUnresolved(expirationDays)||(expirationDays<MEMORY_EXPIRATION_DAYS_MIN||expirationDays>MEMORY_EXPIRATION_DAYS_MAX)&&errors.push(`Memory expiration days must be between ${MEMORY_EXPIRATION_DAYS_MIN} and ${MEMORY_EXPIRATION_DAYS_MAX}`),errors};_renderMemoryStrategies(){if(!(!this.memoryStrategies||this.memoryStrategies.length===0))return this.memoryStrategies.map(ms=>ms.render())}static{__runInitializers(_classThis,_classExtraInitializers)}};return Memory2=_classThis})();exports.Memory=Memory;