Skip to content

Possible to supply AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN other than through Environment Variables? #1679

Answered by jbelkins
StevoSM asked this question in Q&A
Discussion options

You must be logged in to vote

Here is a code sample that allows you to supply your own credentials programmatically. The example is for STS, but S3 should configure the exact same way.

import AWSSTS
import SmithyIdentity

        let region = "us-east-1"  // or whatever region you are using
        let credentials = AWSCredentialIdentity(accessKey: "", secret: "", expiration: nil, sessionToken: nil)  // your credentials here
        let identityResolver = try StaticAWSCredentialIdentityResolver(credentials)
        let config = try await STSClient.STSClientConfiguration(awsCredentialIdentityResolver: identityResolver, region: region)
        let client = STSClient(config: config)
        // now use your client to call…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@StevoSM
Comment options

Answer selected by StevoSM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants