Published
Edited
Aug 11, 2022
1 fork
Importers
10 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
listUsers = async () => {
const response = await iam.listUsers().promise();
return response.Users;
}
Insert cell
createUser = async username => {
const response = await iam
.createUser({
UserName: username
})
.promise();
return response.User;
}
Insert cell
deleteUser = async username => {
const response = await iam
.deleteUser({
UserName: username
})
.promise();
}
Insert cell
getUser = async username => {
const response = await iam
.getUser({
...(username && { UserName: username })
})
.promise();
return response.User;
}
Insert cell
Insert cell
listAccessKeys = async username => {
const response = await iam
.listAccessKeys({
UserName: username
})
.promise();
return response.AccessKeyMetadata;
}
Insert cell
/*https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#createAccessKey-property*/
createAccessKey = async username => {
const response = await iam
.createAccessKey({
UserName: username
})
.promise();
return response.AccessKey;
}
Insert cell
deleteAccessKey = async (username, accessKeyId) => {
const response = await iam
.deleteAccessKey({
UserName: username,
AccessKeyId: accessKeyId
})
.promise();
}
Insert cell
Insert cell
listUserTags = async username => {
const response = await iam
.listUserTags({
UserName: username
})
.promise();
return response.Tags.reduce(
(acc, r) =>
Object.defineProperty(acc, r.Key, { value: r.Value, enumerable: true }),
{}
);
}
Insert cell
// https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html#tagUser-property
tagUser = async (username, tagDictionary) => {
const response = await iam
.tagUser({
Tags: Object.entries(tagDictionary).map(e => ({
Key: e[0],
Value: e[1]
})),
UserName: username
})
.promise();
return response.Tags;
}
Insert cell
untagUser = async (username, keyArray) => {
const response = await iam
.untagUser({
TagKeys: keyArray,
UserName: username
})
.promise();
return response.Tags;
}
Insert cell
Insert cell
listGroups = async username => {
const response = await iam.listGroups().promise();
return response.Groups;
}
Insert cell
listGroupsForUser = async username => {
const response = await iam
.listGroupsForUser({
UserName: username
})
.promise();
return response.Groups;
}
Insert cell
addUserToGroup = async (username, group) => {
return await iam
.addUserToGroup({
UserName: username,
GroupName: group
})
.promise();
}
Insert cell
removeUserFromGroup = async (username, group) => {
return await iam
.removeUserFromGroup({
UserName: username,
GroupName: group
})
.promise();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
async function hasBucket(name) {
return s3
.getBucketLocation({
Bucket: name
})
.promise()
.then(() => true)
.catch(err => false);
}
Insert cell
listObjects = async function (bucket, prefix = undefined, options = {}) {
const response = await s3
.listObjectsV2({
Bucket: bucket,
Delimiter: "/",
...(prefix && { Prefix: prefix }),
...options
})
.promise();
return response.CommonPrefixes;
}
Insert cell
getObject = async (bucket, path) => {
const response = await s3
.getObject({
Bucket: bucket,
Key: path
})
.promise();
return response.Body;
}
Insert cell
putObject = async (bucket, path, value, options) => {
const s3Options = { ...options };
delete s3Options["tags"];
return s3
.putObject({
Bucket: bucket,
Key: path,
Body: value,
...(options?.tags && {
Tagging: Object.entries(options.tags)
.map((e) => `${e[0]}=${e[1]}`)
.join("&")
}),
...s3Options
})
.promise();
}
Insert cell
md`# CloudFront

`
Insert cell
cloudFront = login || new AWS.CloudFront()
Insert cell
createInvalidation = (distributionId, paths = []) => {
const operationId = randomId(16);
return cloudFront
.createInvalidation({
DistributionId: distributionId,
InvalidationBatch: {
CallerReference: operationId,
Paths: {
Quantity: paths.length,
Items: paths
}
}
})
.promise();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more