Skip to content

Files downloaded from s3 are cached, and do not reflect actual bucket content #1913

@hughperkins

Description

@hughperkins

Describe the bug

  • use AWSS3, in Swift, to download a file from s3, e.g. a text file containing "hello"
  • use awscli to update the file to different content, e.g. "world"
  • use AWSS3, in Swift, to download the file again
  • => notice that the file contents are the earlier contents, not the new contents

Note that restarting the Swift application is NOT sufficient to reset the cache.

Expected Behavior

  • using AWSS3 to download a file from a bucket will retrieve the file from the bucket, not a locally cached copy

Current Behavior

  • using AWSS3 to downlaod a file from a bucket results in the file being cached locally, and updated versions in the bucket are not returned currently

Reproduction Steps

import Cocoa
import ClientRuntime
import AWSS3
import AWSClientRuntime
import AWSSDKIdentity
import AWSSTS
import AwsCommonRuntimeKit

class S3CacheVC: NSViewController {
    private var s3Client: S3Client!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        Task {
            do {
                let accessKey = "[put your acces key]"
                let secretKey = "[put your secret key]"
                let region = "us-east-1"
                let bucketName = "hughtests3apps"
                let keyName = "bar/foo.txt"
                
                let identity = AWSCredentialIdentity(accessKey: accessKey, secret: secretKey)
                let credentialsProvider = try StaticAWSCredentialIdentityResolver(identity)
                
                let config = try await S3Client.S3ClientConfiguration(
                    awsCredentialIdentityResolver: credentialsProvider,
                    awsRetryMode: .standard,
                    maxAttempts: 3,
                    region: region
                )
                s3Client = S3Client(config: config)
                
                let input = GetObjectInput(
                    bucket: bucketName,
                    key: keyName
                )
                let output = try await s3Client.getObject(input: input)
                let data = try await output.body?.readData()
                let contents = String(data: data!, encoding: .utf8)
                print("contents", contents ?? "nil")
            } catch {
                print(error)
            }
        }
    }
}

Output of this program:

contents Hello world

Now run from commandline:

aws s3 cp s3://hughtests3apps/bar/foo.txt /tmp/temp.txt && cat /tmp/temp.txt
download: s3://hughtests3apps/bar/foo.txt to ../../../../../../tmp/temp.txt
yellow

Possible Solution

  • remove the cache on downloaded s3 objects. It's not part of s3 client spec to have a cache in any case I feel

Additional Information/Context

No response

AWS SWIFT SDK version used

1.2.48

Compiler and Version used

xcode 16.2

Operating System and version

mac osx 15.3.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions