Skip to content

Instantly share code, notes, and snippets.

# needs Python3, though easily adapted
from __future__ import unicode_literals
import boto3
def main():
session = boto3.session.Session(profile_name='aws_credentials_profile')
ec2 = session.resource('ec2')
# define instance parameters
@zdotfive
zdotfive / cognito-test.py
Created January 29, 2022 07:42 — forked from bgdnlp/cognito-test.py
Sign up and log in to Cognito, check tokens, then call an API. Details: https://www.neant.ro/aws/working-with-cognito-and-api-gateway-in-python.html
#!/usr/bin/env python3
# Demonstrates the use of Python to work with Cognito.
# Create a new a user, log in, check tokens and call an API.
# The purpose was to learn about Cognito. Security has been
# circumvented in the interest of keeping it simple.
# Notably, the authentication procedure uses the most insecure
# method. This code is not intended for use in production.
#
# https://www.neant.ro/aws/working-with-cognito-and-api-gateway-in-python.html
import os
import json
import boto3
def lambda_handler(event, context):
if event:
messages_to_reprocess = []
batch_failure_response = {}
for record in event["Records"]:
try:
import os
import json
import boto3
def lambda_handler(event, context):
region_name = os.environ['AWS_REGION']
if event:
sqs = boto3.resource('sqs', region_name=region_name)
queue_name = event['Records'][0]['eventSourceARN'].split(':')[-1]
queue = sqs.get_queue_by_name(QueueName=queue_name)
import os
import json
import boto3
def lambda_handler(event, context):
region_name = os.environ['AWS_REGION']
if event:
sqs = boto3.client('sqs', region_name=region_name)
queue_name = event['Records'][0]['eventSourceARN'].split(':')[-1]
queue_url = sqs.get_queue_url(
import json
import boto3
def lambda_handler(event, context):
region_name = os.environ['AWS_REGION']
if event:
for record in event['Records']:
body = record['body']
# process message
return {