Skip to content

Instantly share code, notes, and snippets.

# Supply a custom prompt to a LangChain QA Chain
system_template = """Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.
{context}
Question: {question}
Helpful Answer:"""
messages = [
SystemMessagePromptTemplate.from_template(system_template),
HumanMessagePromptTemplate.from_template("{question}"),
import boto3
# This code deletes buckets on AWS S3.
# It is designed to be run on a local machine with credentials for an AWS account that has the
# necessary permissions to delete buckets.
# It will delete the contents of the buckets before deleting the bucket itself.
# It will not attempt to delete a bucket that does not exist.
# BUCKETS is a list of bucket names that should be deleted. If a bucket in the list does not
# exist, it will be skipped.
@samkeen
samkeen / logger.py
Created March 13, 2020 22:02 — forked from impredicative/logger.py
Python json logging using structlog and stdlib logging
"""
Usage example:
from logger import get_logger
log = get_logger()
log.info('my_event', my_key1='val 1', my_key2=5, my_key3=[1, 2, 3], my_key4={'a': 1, 'b': 2})
List of metadata keys in each log message:
event
_func
Ec2InPrivateSubnetWithouttNatGtwy:
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref LatestAmiId
InstanceType: !Ref InstanceType
# KeyName: NO SSH Key needed
IamInstanceProfile: !Ref Ec2InstanceProfile
NetworkInterfaces:
# The SSM Agent running on the EC2 instances must be able to connect to Session Manager's
# public endpoint. You can also set up a PrivateLink connection to allow instances running
env:
variables:
LAMBDA_PKG_BUCKET_PREFIX: mia
phases:
install:
commands:
# replace json_api value with parsed value
for key in json_encoded_key_names:
if key in pdp_output.get('product-attributes') and pdp_output['product-attributes'][key] is not None:
try:
pdp_output['product-attributes'][key] = json.loads(pdp_output['product-attributes'][key])
except json.decoder.JSONDecodeError as e:
record_fault('call-resp-processing.atg.missing-required-data',
f"""Invalid JSON: {key} in pdp_output['product-attributes'] Reason:
{e.msg} Data: {pdp_output['product-attributes'][key]}""")
@samkeen
samkeen / vpc-with-NAT-gateway-bastion-host.template.json
Last active June 22, 2018 14:20
Same as lean version, but with NAT Gateway and Bastion host
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "VPC Across 3 AZs",
"Parameters": {
"EnvName": {
"Type": "String",
"Default": "Dev",
"AllowedValues": [
"Dev", "Test", "Prod"
],
@samkeen
samkeen / vpc-lean.template.json
Last active March 20, 2016 04:23
Lean version of 3 subnet VPC Template
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "VPC Across 3 AZs",
"Parameters": {
"EnvName": {
"Type": "String",
"Default": "Dev",
"AllowedValues": [
"Dev", "Test", "Prod"
],
@samkeen
samkeen / cw-monitor-memusage.py
Last active November 6, 2015 16:35 — forked from shevron/LICENSE
Send EC2 instance memory usage stats to CloudWatch using boto and IAM Roles
#!/usr/bin/env python
'''
Send memory usage metrics to Amazon CloudWatch
This is intended to run on an Amazon EC2 instance and requires an IAM
role allowing to write CloudWatch metrics. Alternatively, you can create
a boto credentials file and rely on it instead.
Original idea based on https://github.com/colinbjohnson/aws-missing-tools

Random Notes I'll organize later

Troubleshooting

YUM timeout

Could not retrieve mirrorlist http://repo.us-west-2.amazonaws.com/latest/main/mirror.list error was
    amazon-ebs: 12: Timeout on http://repo.us-west-2.amazonaws.com/latest/main/mirror.list: (28, 'Connection timed out after 10001 milliseconds')