Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS python SDK getting invoked more than once with scheduled cloudwatch event #6

Open
ghost opened this issue Oct 29, 2019 · 0 comments

Comments

@ghost
Copy link

ghost commented Oct 29, 2019

This issue is with respect to another issue I had logged a few days ago [https://github.com//issues/292].

I am invoking a lambda from another lambda using python SDK. Both the lambdas belong to the same VPC. The trigger lambda only contains a python script that invokes the second lambda (loader_development) and the code for that is as under:

from __future__ import print_function

import json
import logging
import os
from urllib2 import urlopen,Request,HTTPError
import boto3
import botocore.config

logger = logging.getLogger()
logger.setLevel(logging.INFO)
region = os.environ['AWS_REGION']
cfg = botocore.config.Config(retries={'max_attempts': 0})
def lambda_handler(event, context):
    logger.info('starting loading')
    invokeLambda = boto3.client('lambda', region_name = 'us-east-1', config=cfg)  
    request = {'resource':'/bucketstatus/latest','path':'/bucketstatus/latest','httpMethod':'GET', 'requestContext': {'requestId': context.aws_request_id,'identity': {'userArn': context.invoked_function_arn}}}
    invoke_response = invokeLambda.invoke(FunctionName='loader_development',
                                           InvocationType='RequestResponse',
                                           Payload=json.dumps(request))
    print(invoke_response['Payload'].read())

logger.info('Process Complete')

But, "starting loading" is printing thrice so I think this script is getting invoked thrice. Previously only the loader_development lambda was being retried for which I set the value of max retry attempts to 0. (FYI: I have a cloudwatch event enabled for my trigger cron(0/30 7-9 * * ? *) so does the cloudwatch event also have a retry mechanism?) How do I disable this cloudwatch event from triggering my script more than once?

P.S. This code works if I don't have a scheduled cloudwatch event.

@ghost ghost changed the title AWS python SDK invoking AWS lambda function more than once with scheduled cloudwatch event AWS python SDK getting invoked more than once with scheduled cloudwatch event Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants