-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathput-role-policy.js
More file actions
63 lines (56 loc) · 1.64 KB
/
put-role-policy.js
File metadata and controls
63 lines (56 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { fileURLToPath } from "node:url";
// snippet-start:[javascript.v3.iam.actions.PutRolePolicy]
import { PutRolePolicyCommand, IAMClient } from "@aws-sdk/client-iam";
const examplePolicyDocument = JSON.stringify({
Version: "2012-10-17",
Statement: [
{
Sid: "VisualEditor0",
Effect: "Allow",
Action: [
"s3:ListBucketMultipartUploads",
"s3:ListBucketVersions",
"s3:ListBucket",
"s3:ListMultipartUploadParts",
],
Resource: "arn:aws:s3:::amzn-s3-demo-bucket",
},
{
Sid: "VisualEditor1",
Effect: "Allow",
Action: [
"s3:ListStorageLensConfigurations",
"s3:ListAccessPointsForObjectLambda",
"s3:ListAllMyBuckets",
"s3:ListAccessPoints",
"s3:ListJobs",
"s3:ListMultiRegionAccessPoints",
],
Resource: "*",
},
],
});
const client = new IAMClient({});
/**
*
* @param {string} roleName
* @param {string} policyName
* @param {string} policyDocument
*/
export const putRolePolicy = async (roleName, policyName, policyDocument) => {
const command = new PutRolePolicyCommand({
RoleName: roleName,
PolicyName: policyName,
PolicyDocument: policyDocument,
});
const response = await client.send(command);
console.log(response);
return response;
};
// snippet-end:[javascript.v3.iam.actions.PutRolePolicy]
// Invoke main function if this file was run directly.
if (process.argv[1] === fileURLToPath(import.meta.url)) {
putRolePolicy("ROLE_NAME", "POLICY_NAME", examplePolicyDocument);
}