Skip to content

Instantly share code, notes, and snippets.

View greencamp20552's full-sized avatar

greencamp20552

View GitHub Profile
import boto3
# Configure your AWS credentials
aws_access_key_id = 'YOUR_ACCESS_KEY_ID'
aws_secret_access_key = 'YOUR_SECRET_ACCESS_KEY'
aws_region = 'us-east-1' # Replace with your desired AWS region
# Create a CodeDeploy client
codedeploy = boto3.client('codedeploy', region_name=aws_region, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:Describe*",
"dynamodb:Get*",
"dynamodb:List*",
"dynamodb:Batch*",
@greencamp20552
greencamp20552 / iam_create_user.sh
Last active July 14, 2023 06:44
aws-architect-professional-iam
aws iam create-user --user-name Mary
@greencamp20552
greencamp20552 / aws_s3_add_lifecycle_rule.py
Created July 12, 2023 04:43
aws-architect-professional
import boto3
from botocore.exceptions import ClientError
bucket_name = "test-bucket"
folder_paths = ["test_folder","test_folder1", "test_folder2"]
expiration = 1
def add_lifecycle_rule_for_s3(bucket_name,folder_paths):
session = boto3.session.Session()
s3_client = session.client('s3')
try:
@greencamp20552
greencamp20552 / create_user_with_aws_cognito.py
Created July 11, 2023 10:26
aws-architect-professional
import boto3
aws_client = boto3.client('cognito-idp',
region_name = CONFIG["cognito"]["region"]
)
response = aws_client.admin_create_user(
UserPoolId = CONFIG["cognito"]["pool_id"],
Username = email,
UserAttributes = [
{"Name": "first_name", "Value": first_name},
{"Name": "last_name", "Value": last_name},
@greencamp20552
greencamp20552 / aws_cognito.py
Created July 11, 2023 10:16
aws-architect-professional
import boto3
import boto
#boto.set_stream_logger('foo')
import json
client = boto3.client('cognito-identity','us-east-1')
resp = client.get_id(AccountId='<ACCNTID>',IdentityPoolId='<IDPOOLID>')
print "\nIdentity ID: %s"%(resp['IdentityId'])
print "\nRequest ID: %s"%(resp['ResponseMetadata']['RequestId'])
resp = client.get_open_id_token(IdentityId=resp['IdentityId'])
token = resp['Token']
@greencamp20552
greencamp20552 / AWS-Security-Token-Service.py
Created July 11, 2023 09:37
aws-architect-professional
from boto.s3.connection import S3Connection
from boto.sts import STSConnection
user = sts.get_federation_token('user1')
s3connection = S3Connection(user.credentials.access_key, user.credentials.secret_key, security_token=user.credentials.session_token)
s3connection.create_bucket('dev.professional')
response = client.list_attached_role_policies(
RoleName='string',
PathPrefix='string',
Marker='string',
MaxItems=123
)
@greencamp20552
greencamp20552 / iam_attach_policy_to_group.py
Last active July 11, 2023 09:43
aws-architect-professional
def attach_group_policy(policy_arn, group_name):
iam = boto3.client("iam")
response = iam.attach_group_policy(
GroupName=group_name,
PolicyArn=policy_arn
)
print(response)
@greencamp20552
greencamp20552 / iam_list_policy.py
Created July 10, 2023 09:40
aws-architect-professional
def list_policies():
iam = boto3.client("iam")
paginator = iam.get_paginator('list_policies')
for response in paginator.paginate(Scope="AWS"):
for policy in response["Policies"]:
print(f"Policy Name: {policy['PolicyName']} ARN: {policy['Arn']}")