Last active
July 12, 2021 07:24
-
-
Save wesww/8760eff3aaa74b3a3bbbf6359673baf6 to your computer and use it in GitHub Desktop.
AWS JS libs without an Amplify backend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Auth from '@aws-amplify/auth' | |
import Analytics from '@aws-amplify/analytics' | |
Auth.configure({ | |
region: 'us-east-1', | |
identityPoolId: 'us-east-1:xxxx...', | |
}) | |
Analytics.configure({ | |
AWSPinpoint: { | |
appId: 'appIdKey', | |
region: 'us-east-1' | |
} | |
}) | |
Analytics.record({ name: 'Hello' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Auth.configure({ | |
region: 'us-east-1', | |
identityPoolId: 'us-east-1:xxxx...' | |
}) | |
Analytics.configure({ | |
AWSPinpoint: { | |
appId: 'appIdKey', | |
region: 'us-east-1' | |
} | |
}) | |
Analytics.record({ name: 'Hello' }) | |
Storage.configure({ | |
AWSS3: { | |
bucket: 'bucketname', | |
region: 'us-east-1' | |
} | |
}) | |
Storage.get('s3keyname', { download: true }) | |
.then(result => console.log(result)) | |
.catch(err => console.log(err)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Auth from '@aws-amplify/auth' | |
import Storage from '@aws-amplify/storage' | |
Auth.configure({ | |
region: 'us-east-1', | |
identityPoolId: 'us-east-1:xxxx...' | |
}) | |
Storage.configure({ | |
AWSS3: { | |
bucket: 'bucketname', | |
region: 'us-east-1' | |
} | |
}) | |
Storage.get('s3keyname', { download: true }) | |
.then(result => console.log(result)) | |
.catch(err => console.log(err)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3' | |
import { CognitoIdentityClient } from '@aws-sdk/client-cognito-identity' | |
import { fromCognitoIdentityPool } from '@aws-sdk/credential-provider-cognito-identity' | |
const credentials = fromCognitoIdentityPool({ | |
client: new CognitoIdentityClient({ | |
region: 'us-east-1' | |
}), | |
identityPoolId: 'us-east-1:xxxx...' | |
}) | |
const s3Client = new S3Client({ | |
credentials, | |
region: 'us-east-1' | |
}) | |
s3Client.send(new GetObjectCommand({ | |
Bucket: 'bucketname', | |
Key: 'public/s3keyname' | |
})).then((data) => console.log(data)) | |
.catch((err) => console.log(err)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Podfile | |
// pod 'AWSCognito' | |
// pod 'AWSS3' | |
import AWSCognito | |
import AWSS3 | |
func getS3Object() -> Any { | |
let cognitoIdentityPool = "us-east-1:xxxx..." | |
let credentialsProvider:AWSCognitoCredentialsProvider = AWSCognitoCredentialsProvider( | |
regionType: .USEast1, | |
identityPoolId: cognitoIdentityPool | |
) | |
let configuration = AWSServiceConfiguration( | |
region: .USEast1, | |
credentialsProvider: credentialsProvider | |
) | |
AWSServiceManager.default().defaultServiceConfiguration = configuration | |
let request = AWSS3GetObjectRequest() | |
request?.bucket = "bucketname" | |
request?.key = "public/s3keyname" | |
return AWSS3.default().getObject(request!).continueWith { | |
(task) -> Any? in | |
if let error = task.error { | |
print("Error occurred: \(error)") | |
return nil | |
} | |
if let result = task.result { | |
print("Result: \(result)") | |
return result | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment