0
I am trying to create a automated process of accepting snapchat invatation to organization. The way it works is we have an email and we get invites to different organizations. Then I use AWS lambda to fetch the email from Workmail and extract the invatation link. This part works fine.
The next part is simulating the accepting the invite. Because snapchat have captcha I can’t login into snapchat but what I figured is I can perhaps use google chrome profile session which is already logged in into snapchat. So I use Docker to dockerize my code and all of the directories I need, my Docker file looks like this:
FROM amazon/aws-lambda-python:3.12
# Install chrome dependencies and 7-Zip
RUN dnf install -y atk cups-libs gtk3 libXcomposite alsa-lib \
libXcursor libXdamage libXext libXi libXrandr libXScrnSaver \
libXtst pango at-spi2-atk libXt xorg-x11-server-Xvfb \
xorg-x11-xauth dbus-glib dbus-glib-devel nss mesa-libgbm jq unzip
RUN dnf install -y p7zip p7zip-plugins
# Set the working directory
WORKDIR ./
# Copy and run the chrome installer script
COPY ./chrome-installer.sh ./chrome-installer.sh
RUN chmod +x ./chrome-installer.sh
RUN ./chrome-installer.sh
RUN rm ./chrome-installer.sh
# Install selenium
RUN pip install selenium
# Install AWS CLI
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
./aws/install
RUN mkdir -p .config/google-chrome
RUN mkdir -p cookie_temp
# ARG AWS_ACCESS_KEY_ID
# ARG AWS_SECRET_ACCESS_KEY
# Set environment variables from build arguments
ENV AWS_ACCESS_KEY_ID=
ENV AWS_SECRET_ACCESS_KEY=
ENV AWS_DEFAULT_REGION=eu-west-1
# Download the zip file from S3 using AWS CLI
RUN aws s3 cp s3://bucket/google_chromium/Profile1.7z ./.config/google-chrome/Profile1.7z
# Unzip the file
RUN 7z x ./.config/google-chrome/Profile1.7z -o./.config/google-chrome/
RUN chown -R root:root .config/google-chrome
RUN chmod -R 755 .config/google-chrome
RUN chmod -R 755 cookie_temp
RUN chmod o+rx .config/google-chrome
RUN chmod o+rx cookie_temp
# Clean up
RUN rm ./.config/google-chrome/Profile1.7z
COPY cookie_temp/cookies.pkl cookie_temp/
# Copy the main application code
COPY lambda_function.py ./
COPY ssm.py ./
COPY headless_browser.py ./
RUN ls -l ./
# Command to run the Lambda function
CMD [ "lambda_function.lambda_handler" ]
I am trying to create a automated process of accepting snapchat invatation to organization. The way it works is we have an email and we get invites to different organizations. Then I use AWS lambda to fetch the email from Workmail and extract the invatation link. This part works fine.
The next part is simulating the accepting the invite. Because snapchat have captcha I can’t login into snapchat but what I figured is I can perhaps use google chrome profile session which is already logged in into snapchat. So I use Docker to dockerize my code and all of the directories I need, my Docker file looks like this:
FROM amazon/aws-lambda-python:3.12
# Install chrome dependencies and 7-Zip
RUN dnf install -y atk cups-libs gtk3 libXcomposite alsa-lib \
libXcursor libXdamage libXext libXi libXrandr libXScrnSaver \
libXtst pango at-spi2-atk libXt xorg-x11-server-Xvfb \
xorg-x11-xauth dbus-glib dbus-glib-devel nss mesa-libgbm jq unzip
RUN dnf install -y p7zip p7zip-plugins
# Set the working directory
WORKDIR ./
# Copy and run the chrome installer script
COPY ./chrome-installer.sh ./chrome-installer.sh
RUN chmod +x ./chrome-installer.sh
RUN ./chrome-installer.sh
RUN rm ./chrome-installer.sh
# Install selenium
RUN pip install selenium
# Install AWS CLI
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
./aws/install
RUN mkdir -p .config/google-chrome
RUN mkdir -p cookie_temp
# ARG AWS_ACCESS_KEY_ID
# ARG AWS_SECRET_ACCESS_KEY
# Set environment variables from build arguments
ENV AWS_ACCESS_KEY_ID=
ENV AWS_SECRET_ACCESS_KEY=
ENV AWS_DEFAULT_REGION=eu-west-1
# Download the zip file from S3 using AWS CLI
RUN aws s3 cp s3://bucket/google_chromium/Profile1.7z ./.config/google-chrome/Profile1.7z
# Unzip the file
RUN 7z x ./.config/google-chrome/Profile1.7z -o./.config/google-chrome/
RUN chown -R root:root .config/google-chrome
RUN chmod -R 755 .config/google-chrome
RUN chmod -R 755 cookie_temp
RUN chmod o+rx .config/google-chrome
RUN chmod o+rx cookie_temp
# Clean up
RUN rm ./.config/google-chrome/Profile1.7z
COPY cookie_temp/cookies.pkl cookie_temp/
# Copy the main application code
COPY lambda_function.py ./
COPY ssm.py ./
COPY headless_browser.py ./
RUN ls -l ./
# Command to run the Lambda function
CMD [ "lambda_function.lambda_handler" ]
So I download a zipped folder that contains Profile 1 which has all cookies and sessions. Then I unzip it and I am trying to access the content of it. But this is were I have an issue
Instead of webdriver being initiated, it always gets an error, in other words I can’t start the webdriver. Here is my script code:
class HeadlessBrowser():
def __init__(self, user_creds, invatation_url):
# Add a short delay to ensure Chrome processes are terminated
time.sleep(4)
print('KILLED')
#Clean up the profile directory
profile_path = ".config/google-chrome"
#Set up headless browser options
chrome_options = ChromeOptions()
chrome_options.add_argument("--headless=new")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--disable-dev-tools")
chrome_options.add_argument("--no-zygote")
#profile_path = "C:/root/.config/google-chrome"
chrome_options.add_argument(f"--user-data-dir={profile_path}")
#chrome_options.add_argument("--profile-directory=Default")
chrome_options.add_argument("--remote-debugging-pipe")
chrome_options.add_argument("--verbose")
chrome_options.add_argument('--start-maximized')
chrome_options.add_argument("--log-path=/tmp")
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.binary_location = "/opt/chrome/chrome-linux64/chrome"
service = Service(
executable_path="/opt/chrome-driver/chromedriver-linux64/chromedriver",
service_log_path="/tmp/chromedriver.log"
)
self.user_creds = user_creds
self.invatation_url = invatation_url
print('REACHED HERE2')
self.driver = webdriver.Chrome(
service=service,
options=chrome_options
)
Does anyhone has any experiance with these kind of things? I am kinda new to Docker so any help will be greatly appreciated!