1. AWS Role used to create an aws lambda. as simple as possible.

    Python

    To create an AWS Lambda function, you first need an IAM Role that the Lambda function can assume which grants it the necessary permissions to run. Below is a simple Pulumi program in Python that creates an IAM Role with a basic AWS Lambda execution policy and then a Lambda function that assumes this role.

    import pulumi import pulumi_aws as aws # Create an IAM role lambda_role = aws.iam.Role('lambdaRole', assume_role_policy="""{ "Version": "2012-10-17", "Statement": [{ "Action": "sts:AssumeRole", "Effect": "Allow", "Principal": { "Service": "lambda.amazonaws.com" } }] }""") # Attach the AWS Lambda Basic Execution Role policy to the IAM role lambda_execution_policy_attachment = aws.iam.RolePolicyAttachment('lambdaExecutionPolicyAttachment', role=lambda_role.name, policy_arn='arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole') # Here we assume you have a zipped Lambda code package in 'lambda_function_payload.zip' lambda_function = aws.lambda_.Function('myLambdaFunction', role=lambda_role.arn, runtime='python3.8', handler='index.handler', # replace with your handler code=pulumi.FileArchive('./lambda_function_payload.zip')) # Export the name of the lambda function pulumi.export('lambda_function_name', lambda_function.name)

    This program sets up a Lambda function with a role that has permissions to run Lambda functions. The IAM role's trust policy allows AWS Lambda to assume the role, and the policy attachment ensures the role has the necessary permissions. Make sure to replace 'index.handler' with the appropriate handler for your Lambda function and './lambda_function_payload.zip' with the path to your Lambda function's deployment package.