amazon-web-services

Building an AMI using Packer with Python & Python modules (using pip) installed via powershell script

Building an AMI using Packer with Python & Python modules (using pip) installed via powershell script Question: Using Packer, I am trying to create a Windows AMI with Python + the cryptography module installed. Here is the installation command I’m using for Python: Invoke-Expression "python-3.6.8-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0" Standalone that works fine. If I …

Total answers: 1

Create EC2 instance, start instance and run Linux command using Boto3

Create EC2 instance, start instance and run Linux command using Boto3 Question: I am trying to create an AWS EC2 instance, start it, execute a simple Linux command and print the output. However, I keep getting: botocore.errorfactory.InvalidInstanceId: An error occurred (InvalidInstanceId) when calling the SendCommand operation: Instances [[the_instance_id]] not in a valid state for account …

Total answers: 1

Lambda function triggered when adding files to a S3 bucket

Lambda function triggered when adding files to a S3 bucket Question: I am having a problem with the behavior of a Lambda function. Ultimately, I want my lambda function to read some information about json files that I upload to my S3 bucket. Here is a test function: import boto3 import json s3=boto3.client(‘s3’) def LambdaHandler(event,context): …

Total answers: 2

Python Lambda Function returning KeyError

Python Lambda Function returning KeyError Question: Currently trying to create a (simple) Lambda function in AWS using Python 3.8: import json import urllib3 def lambda_handler(event, context): status_code = 200 array_of_rows_to_return = [ ] http = urllib3.PoolManager() try: event_body = event["body"] payload = json.loads(event_body) rows = payload["data"] for row in rows: row_number = row[0] from_currency = …

Total answers: 1

Add key/value pair to existing secrets path in AWS secrets manager without overwriting it using boto3

Add key/value pair to existing secrets path in AWS secrets manager without overwriting it using boto3 Question: I have this code which I’m using to put secrets in AWS secrets manager class SecretsManagerSecret: """Encapsulates Secrets Manager functions.""" def __init__(self, env): """ :param env: Environment on which DAG is running """ self.secretsmanager_client = boto3.client("secretsmanager", region_name="us-east-1") self.env …

Total answers: 1

Saving a json/txt file to S3 from Lambda

Saving a json/txt file to S3 from Lambda Question: I am using lambda to run a program. Once it is run I need to save some data as a json file or txt. I tried to see if there is a way to write a file in lambda and save it but there are no …

Total answers: 1

multiline string substitution in python

Multiline string substitution in Python Question: I am trying this out: account = "11111111111" tenant_name= "Demo" project_name= "demo" sns_access_policy = """{ "Version": "2012-10-17", "Statement": [ { "Sid": "0", "Effect": "Allow", "Principal": { "Service": "codestar-notifications.amazonaws.com" }, "Action": "sns:Publish", "Resource": "arn:aws:sns:eu-west-1:{account_id}:{tenant_name}-{project_name}-pipeline-monitoring" } ] }""" sns_access_policy = sns_access_policy.replace("{account_id}",account).replace("{tenant_name}",tenant_name).replace("{project_name}",project_name) This is doing my work, but I am looking for …

Total answers: 1

Exception handling in AWS – Explicitly ignore some errors?

Exception handling in AWS – Explicitly ignore some errors? Question: I have a Lambda function that’s used to verify the integrity of a file, but for simplicity sake, let’s just assume that it copies a file from a bucket into a bucket upon trigger (lambda gets triggered when it detects file ingestion). The problem that …

Total answers: 1

Unable to import module AWS Lambda Function

Unable to import module AWS Lambda Function Question: I’m having issues running basically any lambda function on AWS as the Lambda Function tool would not be able to import the module. I tried to import the packages as layers – pretty wrong I think. (https://www.linkedin.com/pulse/add-external-python-libraries-aws-lambda-using-layers-gabe-olokun/) Then I’ve tried to import the packages as environments (from …

Total answers: 2