@@ -7,6 +7,8 @@ import { NotFoundError, ValidationError, ForbiddenError } from './errors.js'
77const VIRTUAL_HOST_PATTERN = / ^ ( [ ^ . ] + ) \. s 3 (?: \. ( [ ^ . ] + ) ) ? \. a m a z o n a w s \. c o m $ /
88const PATH_STYLE_PATTERN = / ^ s 3 (?: [ . - ] ( [ ^ . ] + ) ) ? \. a m a z o n a w s \. c o m $ /
99
10+ const s3Client = s3 ( )
11+
1012export const ALTERNATE_ASSETS_EXTENSION = 'https://stac-extensions.github.io/alternate-assets/v1.2.0/schema.json'
1113
1214export const BucketOption = Object . freeze ( {
@@ -112,7 +114,6 @@ const determineS3Region = (asset, itemOrCollection) => {
112114export class AssetProxy {
113115 constructor ( ) {
114116 this . bucketsCache = null
115- this . s3ClientCache = new Map ( )
116117 this . bucketOption = process . env [ 'ASSET_PROXY_BUCKET_OPTION' ] || 'NONE'
117118 this . bucketList = process . env [ 'ASSET_PROXY_BUCKET_LIST' ]
118119 this . urlExpiry = parseInt ( process . env [ 'ASSET_PROXY_URL_EXPIRY' ] || '300' , 10 )
@@ -139,10 +140,8 @@ export class AssetProxy {
139140
140141 case BucketOption . ALL_BUCKETS_IN_ACCOUNT :
141142 try {
142- const region = process . env [ 'AWS_REGION' ] || 'us-west-2'
143- const client = this . getS3Client ( region )
144143 const command = new ListBucketsCommand ( { } )
145- const response = await client . send ( command )
144+ const response = await s3Client . send ( command )
146145 const bucketNames = response . Buckets ?. map ( ( b ) => b . Name )
147146 ?. filter ( ( name ) => typeof name === 'string' ) || [ ]
148147 this . bucketsCache = new Set ( bucketNames )
@@ -158,20 +157,6 @@ export class AssetProxy {
158157 }
159158 }
160159
161- /**
162- * @param {string } region - AWS region
163- * @returns {Object } S3 client instance
164- */
165- getS3Client ( region ) {
166- if ( this . s3ClientCache . has ( region ) ) {
167- return this . s3ClientCache . get ( region )
168- }
169-
170- const client = s3 ( { region } )
171- this . s3ClientCache . set ( region , client )
172- return client
173- }
174-
175160 /**
176161 * @returns {boolean }
177162 */
@@ -280,20 +265,18 @@ export class AssetProxy {
280265 /**
281266 * @param {string } bucket - S3 bucket name
282267 * @param {string } key - S3 object key
283- * @param {string } region - AWS region
268+ * @param {string } region - AWS region of the S3 bucket
284269 * @returns {Promise<string> } Pre-signed URL
285270 */
286271 async createPresignedUrl ( bucket , key , region ) {
287- const client = this . getS3Client ( region )
288-
289272 const command = new GetObjectCommand ( {
290273 Bucket : bucket ,
291274 Key : key ,
292275 RequestPayer : 'requester'
293276 } )
294277
295- const presignedUrl = await getSignedUrl ( client , command , {
296- expiresIn : this . urlExpiry
278+ const presignedUrl = await getSignedUrl ( s3Client , command , {
279+ expiresIn : this . urlExpiry , signingRegion : region
297280 } )
298281
299282 logger . debug ( 'Generated pre-signed URL for asset' , {
0 commit comments