AWS

Amazon Web Services

User credentials

Instead of sharing the credentials of the AWS account root user, create individual IAM users, granting each user only the permissions they require.

Follow the best practice of using the root user only to create your first IAM user.

There are two types of credentials:

Serverless blog web application architecture

Localstack in Debian

Localstack - lambda and s3

run.sh

   1 zip py-my-function.zip lambda_function.py
   2 awslocal lambda delete-function --function-name py-my-function
   3 awslocal lambda create-function --function-name py-my-function --zip-file fileb://py-my-function.zip --handler lambda_function.lambda_handler  --runtime python3.9 --role arn:aws:iam::000000000000:role/lambda-ex
   4 awslocal lambda invoke --function-name py-my-function --payload '{ "first_name": "Bob","last_name":"Squarepants" }' response.json 
   5 cat response.json

lambda_function.py

   1 import boto3
   2 import os
   3 
   4 def lambda_handler(event, context):
   5     message = 'Hello {} {}!'.format(event['first_name'], event['last_name'])
   6     session = boto3.session.Session()
   7 
   8     s3_client = session.client(
   9         service_name='s3',
  10         aws_access_key_id=os.environ["AWS_ACCESS_KEY_ID"],
  11         aws_secret_access_key=os.environ["AWS_SECRET_ACCESS_KEY"],
  12         endpoint_url='http://localhost:4566',
  13     )
  14 
  15     buckets=[]
  16     for bucket in s3_client.list_buckets()['Buckets']:
  17         buckets.append(bucket['Name'])
  18 
  19     response = s3_client.create_bucket(Bucket='examplebucket')
  20 
  21     body = {
  22         'message' : message,
  23         'buckets' : buckets,
  24         'AWS_ACCESS_KEY_ID' : os.environ["AWS_ACCESS_KEY_ID"],
  25         'AWS_SECRET_ACCESS_KEY' : os.environ["AWS_SECRET_ACCESS_KEY"]
  26     }
  27 
  28     s3_client.put_object(Body=str(body), Bucket='examplebucket', Key='examplebucket/response.txt')
  29     return body

AWS (last edited 2021-11-23 17:32:30 by localhost)