Skip to content

Instantly share code, notes, and snippets.

@emsesc
Created January 23, 2023 21:50
Show Gist options
  • Save emsesc/4169f80b1aae150cb45393ba1a06ec00 to your computer and use it in GitHub Desktop.
Save emsesc/4169f80b1aae150cb45393ba1a06ec00 to your computer and use it in GitHub Desktop.
import json
def lambda_handler(event, context):
# Get the RGB value from the event object (parameter)
rgb = event["queryStringParameters"]["rgb"]
# Split the RGB value into separate red, green, and blue values
split_rgb = rgb.split(',')
# Access each hex value by indexes
red = int(split_rgb[0])
green = int(split_rgb[1])
blue = int(split_rgb[2])
# Convert the red, green, blue color values to hex representation
hex_red = f'{red:02x}'
hex_green = f'{green:02x}'
hex_blue = f'{blue:02x}'
# Concatenate hex values
hex_value = hex_red + hex_green + hex_blue
# Return the hex value
return { 'hex': hex_value}
@emsesc
Copy link
Author

emsesc commented Jan 23, 2023

import json

def lambda_handler(event, context):
    # Get the RGB value from the event object (parameter)
    rgb = event["queryStringParameters"]["rgb"]

    # Split the RGB value into separate red, green, and blue values
    split_rgb = rgb.split(',')
    
    # Access each hex value by indexes (make sure to convert to integer!)
    red = # Your code here
    green = # Your code here
    blue = # Your code here

    # Convert the red, green, blue color values to hex representation
    hex_red = # Your code here
    hex_green = # Your code here
    hex_blue = # Your code here
    
    # Concatenate hex values
    hex_value = # Your code here
    
    # Return the hex value
    return { 'hex': hex_value}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment