I'm trying to create a new user in IAM programatically - amazon-web-services

I'm new to programming. I need to figure out how I can create AWS users, roles and policies programmatically using code.
That task I'm after :
Create a User, Role and Policy
Assign Policy to the Role
Assign Role to the User
Set condition on the Role, that only Users with MFA can assume that Role
Config's should live in S3 bucket
configure a LAMBDA to check the user's role membership and output the result to S3 bucket.
Just trying to figure out where do I start from ? I have a very limited programming experience (can do a bit of PHP).
I have a AWS account, created a user and gave him 'AdministratorAccess' also have user keys for CLI access.
Should I be suing 1)AWS CLI 2) Powershell 3) AWS SDK's 4) AWS API?
Appreciate any help/direction to achieve the above.
Thanks
S

To programmatically create IAM Roles you can use AWS PHP SDK. Refer the IAM Create User section in SDK API reference for more details.

Aside from using specific language AWS SDKs such as suggested by #Ashan, you can do so by using AWS REST API with the following example request:
https://iam.amazonaws.com/?Action=CreateUser
&Path=/division_abc/subdivision_xyz/
&UserName=Bob
&Version=2010-05-08
&AUTHPARAMS
Source - CreateUser

Related

AWS IAM roles Trust Relationships

I want to create fully automated creating of new roles in AWS and connecting this with Snowflake. To connect Snowflake with AWS we must edit trust relationships and paste their STORAGE_AWS_EXTERNAL_ID.
Is there any way to do this fully automated?
How about creating a batch script using AWS CLI et SNOW SQL following the steps provided in the Snowflake user guide.
Create your AWS IAM policy and get your policy's arn
Create an AWS IAM role linked to this policy and get the role's arn
Create the snowflake storage integration linked to this role and get STORAGE_AWS_IAM_USER_ARN and STORAGE_AWS_EXTERNAL_ID from DESC INTEGRATION command.
Update the AWS IAM policy with previous values (i.e snowflake's user arn and external id).

How to restrict AWS CLI Access for SSO User

I have SSO configured for my AWS organizational accounts. Have created two accounts(one is dev and the other is prod). How do i restrict AWS CLI Access for my prod accounts SSO users. Tried looking up in their documentation, but couldn't find any.
Can someone help me?
The AWS Command-Line Interface (CLI) can be configured to connect via SSO and assume an IAM Role. It can then be used to make API calls according to the permissions in the chosen IAM Role.
It is not possible to 'restrict' the AWS CLI. Instead, you would restrict the permissions in the IAM Role that is being used.
See: Configuring the AWS CLI to use AWS Single Sign-On - AWS Command Line Interface

Run AWS lambda as an IAM user

I want to run a python project on AWS lambda, but the API (STS:AssumeRole to generate federation URL) which I am trying to call only supports as an IAM user with long-term credentials. It is working on my machine with my IAM keys, but how can I make it run on AWS lambda?
You need to create a role that has similar permissions like your local user. And you can attach the role to your lambda to utilize the STS service.

Why do I have authority in AWS management console but not in AWS CLI for some operations?

I have an AWS root account and I created a IAM user with Administrator policy attached. The problem is that when I make some operations like aws ec2 create-key-pair in the aws-cli, I got UnauthorizedOperation error. But if I sign into the management console using the same IAM user, I can create a key pair with no problem.
I double checked my access key id and secret access key is right. I even re-created these and configured in aws-cli to make sure I am using that user account with admin permissions. None of these worked
Is there any setting I'm not aware of that enables aws-cli access permissions?
=============== below is latest update ================
I checked my user info with aws sts get-caller-identify, and it shows my company's account id. I tried to run aws configure again and followed by aws sts get-caller-identity, it still shows that im using my company's account. How do I switch user from CLI?
In case this helps anyone, the issue for me was that my AWS account used MFA. I never considered you'd have to do this on the command-line too. Here is a guide from Amazon on the subject:
How do I use an MFA token to authenticate access to my AWS resources through the AWS CLI?
This is an incredibly big pot hole to step into... but there is a precedence of where aws cli looks for credentials.
IAM credentials not found on AWS CLI
The answer of the question here explains it throughly.

How can I use Jenkins to support S3 IAM roles?

I'm very new to jenkins. I installed the S3 plugin. I wish to use AWS IAM S3 roles to make the plugin work.
However, I can't find any way to configure IAM roles within this plugin. I can see only setting up the access key and secret key.
Has anyone used IAM roles with this plugin?
Kindly help.
Thanks in advance.
IAM roles are assigned to EC2 instances at launch. There's nothing else to configure, thus your S3 plugin should just automatically work. This is dependent on the plugin supporting IAM roles, which it looks like it does according to your link. You will have to assign the correct bucket policy though using the instructions also found at the link.