Socket
Socket
Sign inDemoInstall

@aws-cdk/aws-iam

Package Overview
Dependencies
Maintainers
4
Versions
288
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-cdk/aws-iam

CDK routines for easily assigning correct and minimal IAM permissions


Version published
Weekly downloads
170K
increased by30.43%
Maintainers
4
Weekly downloads
 
Created

Package description

What is @aws-cdk/aws-iam?

@aws-cdk/aws-iam is an AWS Cloud Development Kit (CDK) library that allows you to define AWS Identity and Access Management (IAM) resources in your CDK applications. This package provides constructs for creating and managing IAM roles, users, policies, and groups, enabling you to manage permissions and access control in your AWS environment programmatically.

What are @aws-cdk/aws-iam's main functionalities?

Create IAM Role

This code sample demonstrates how to create an IAM role that can be assumed by EC2 instances and has read-only access to Amazon S3.

const iam = require('@aws-cdk/aws-iam');
const cdk = require('@aws-cdk/core');

class MyStack extends cdk.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    new iam.Role(this, 'MyRole', {
      assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com'),
      managedPolicies: [
        iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonS3ReadOnlyAccess')
      ]
    });
  }
}

const app = new cdk.App();
new MyStack(app, 'MyStack');

Create IAM User

This code sample demonstrates how to create an IAM user with administrator access.

const iam = require('@aws-cdk/aws-iam');
const cdk = require('@aws-cdk/core');

class MyStack extends cdk.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    new iam.User(this, 'MyUser', {
      userName: 'my-user',
      managedPolicies: [
        iam.ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess')
      ]
    });
  }
}

const app = new cdk.App();
new MyStack(app, 'MyStack');

Attach Inline Policy to Role

This code sample demonstrates how to create an IAM role and attach an inline policy that allows listing objects in a specific S3 bucket.

const iam = require('@aws-cdk/aws-iam');
const cdk = require('@aws-cdk/core');

class MyStack extends cdk.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    const role = new iam.Role(this, 'MyRole', {
      assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com')
    });

    role.addToPolicy(new iam.PolicyStatement({
      actions: ['s3:ListBucket'],
      resources: ['arn:aws:s3:::my-bucket']
    }));
  }
}

const app = new cdk.App();
new MyStack(app, 'MyStack');

Other packages similar to @aws-cdk/aws-iam

Changelog

Source

0.9.1 (2018-09-13)

Bug Fixes

  • aws-cdk: Fix proxy support for account lookup (#693) (5468225), closes #645

Features

  • aws-ec2 BREAKING: Move LoadBalancer to aws-elasticloadbalancing package (#705) (4bd1cf2)
  • aws-serverless BREAKING: Rename @aws-cdk/aws-serverless to @aws-cdk/aws-sam (#704) (3a67d5d)
  • aws-dynamodb: Support DynamoDB TTL (#691) (35b6206)
  • aws-dynamodb: Support DynamoDB PITR (#701) (7a4d7b7)
  • aws-ecr: Add support for ECR repositories (#697) (c6c09bf)
  • aws-lambda: Add support for XRay Tracing (#675) (b4435cc)
  • cfnspec: Add DeploymentPreference Patch for SAM Spec (#681) (#681) (f96c487)

Readme

Source

AWS IAM Construct Library

Define a role and add permissions to it. This will automatically create and attach an IAM policy to the role:

const role = new Role(this, 'MyRole', {
  assumedBy: new ServicePrincipal('sns.amazonaws.com')
});
role.addPermission(new Permission('*', 'lambda:InvokeFunction'));

Define a policy and attach it to groups, users and roles. Note that it is possible to attach the policy either by calling xxx.attachPolicy(policy) or policy.attachToXxx(xxx).

const user = new User(this, 'MyUser', { password: '1234' });
const group = new Group(this, 'MyGroup');

const policy = new Policy(this, 'MyPolicy');
policy.attachToUser(user);
group.attachPolicy(policy);

Managed policies can be attached using xxx.attachManagedPolicy(arn):

const group = new Group(this, 'MyGroup');
group.attachManagedPolicy('arn:aws:iam::aws:policy/AdministratorAccess');

Features

  • Policy name uniqueness is enforced. If two policies by the same name are attached to the same principal, the attachment will fail.
  • Policy names are not required - the CDK logical ID will be used and ensured to be unique.

Keywords

FAQs

Package last updated on 14 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc