Пример #1
0
def update_cfg(args):
    """Update the configuration (everything but code) of the lambda function.
    """
    if args.aws_credentials is None:
        # This allows aws roles to be used to create sessions.
        session = boto3.session.Session()
    else:
        session = create_session(args.aws_credentials)
    client = session.client('lambda')

    kwargs = { 'FunctionName': args.name, 'Runtime': 'python2.7' }
    if args.role is not None:
        kwargs['Role'] = args.role

    if args.handler is not None:
        kwargs['Handler'] = args.handler

    if args.desc is not None:
        kwargs['Description'] = args.desc

    if args.timeout is not None:
        kwargs['Timeout'] = args.timeout

    if args.mem is not None:
        kwargs['MemorySize'] = args.mem

    if args.vpcsubnets is not None and args.vpcsecgroups is not None:
        kwargs['VpcConfig'] = {
            'SubnetIds': args.vpcsubnets, 
            'SecurityGroupIds': args.vpcsecgroups
        }

    resp = client.update_function_configuration(**kwargs)
    print(resp)
Пример #2
0
def update_cfg(args):
    """Update the configuration (everything but code) of the lambda function.
    """
    if args.aws_credentials is None:
        # This allows aws roles to be used to create sessions.
        session = boto3.session.Session()
    else:
        session = create_session(args.aws_credentials)
    client = session.client('lambda')

    kwargs = {'FunctionName': args.name, 'Runtime': 'python2.7'}
    if args.role is not None:
        kwargs['Role'] = args.role

    if args.handler is not None:
        kwargs['Handler'] = args.handler

    if args.desc is not None:
        kwargs['Description'] = args.desc

    if args.timeout is not None:
        kwargs['Timeout'] = args.timeout

    if args.mem is not None:
        kwargs['MemorySize'] = args.mem

    if args.vpcsubnets is not None and args.vpcsecgroups is not None:
        kwargs['VpcConfig'] = {
            'SubnetIds': args.vpcsubnets,
            'SecurityGroupIds': args.vpcsecgroups
        }

    resp = client.update_function_configuration(**kwargs)
    print(resp)
Пример #3
0
def update_code(args):
    """Point the lambda function at new code.
    """
    if args.aws_credentials is None:
        # This allows aws roles to be used to create sessions.
        session = boto3.session.Session()
    else:
        session = create_session(args.aws_credentials)
    client = session.client('lambda')
    resp = client.update_function_code(FunctionName=args.name,
                                       S3Bucket=args.bucket,
                                       S3Key=args.key)
    print(resp)
Пример #4
0
def update_code(args):
    """Point the lambda function at new code.
    """
    if args.aws_credentials is None:
        # This allows aws roles to be used to create sessions.
        session = boto3.session.Session()
    else:
        session = create_session(args.aws_credentials)
    client = session.client('lambda')
    resp = client.update_function_code(
        FunctionName=args.name,
        S3Bucket = args.bucket,
        S3Key = args.key)
    print(resp)
Пример #5
0
def create(args):
    if args.aws_credentials is None:
        # This allows aws roles to be used to create sessions.
        session = boto3.session.Session()
    else:
        session = create_session(args.aws_credentials)
    client = session.client('lambda')
    resp = client.create_function(
        FunctionName=args.name,
        Runtime='python2.7',
        Role=args.role,
        Handler=args.handler,
        Description=args.desc,
        Code={'S3Bucket': args.bucket, 'S3Key': args.key},
        Timeout=args.timeout,
        MemorySize=args.mem,
        VpcConfig={'SubnetIds': args.vpcsubnets, 'SecurityGroupIds': args.vpcsecgroups})
    print(resp)
Пример #6
0
def create(args):
    if args.aws_credentials is None:
        # This allows aws roles to be used to create sessions.
        session = boto3.session.Session()
    else:
        session = create_session(args.aws_credentials)
    client = session.client('lambda')
    resp = client.create_function(FunctionName=args.name,
                                  Runtime='python2.7',
                                  Role=args.role,
                                  Handler=args.handler,
                                  Description=args.desc,
                                  Code={
                                      'S3Bucket': args.bucket,
                                      'S3Key': args.key
                                  },
                                  Timeout=args.timeout,
                                  MemorySize=args.mem,
                                  VpcConfig={
                                      'SubnetIds': args.vpcsubnets,
                                      'SecurityGroupIds': args.vpcsecgroups
                                  })
    print(resp)
Пример #7
0
def setup_parser():
    parser = argparse.ArgumentParser(
        description=
        'Script for deleting lambda functions.  To supply arguments from a file, provide the filename prepended with an `@`.',
        fromfile_prefix_chars='@')
    parser.add_argument(
        '--aws-credentials',
        '-a',
        metavar='<file>',
        default=os.environ.get('AWS_CREDENTIALS'),
        type=argparse.FileType('r'),
        help=
        'File with credentials for connecting to AWS (default: AWS_CREDENTIALS)'
    )
    parser.add_argument('name', help='Name of function.')

    return parser


if __name__ == '__main__':
    parser = setup_parser()
    args = parser.parse_args()

    if args.aws_credentials is None:
        # This allows aws roles to be used to create sessions.
        session = boto3.session.Session()
    else:
        session = create_session(args.aws_credentials)

    delete_func(session, args.name)
Пример #8
0

def setup_parser():
    parser = argparse.ArgumentParser(
        description='Script for deleting lambda functions.  To supply arguments from a file, provide the filename prepended with an `@`.',
        fromfile_prefix_chars = '@')
    parser.add_argument(
        '--aws-credentials', '-a',
        metavar = '<file>',
        default = os.environ.get('AWS_CREDENTIALS'),
        type = argparse.FileType('r'),
        help = 'File with credentials for connecting to AWS (default: AWS_CREDENTIALS)')
    parser.add_argument(
        'name',
        help = 'Name of function.')

    return parser


if __name__ == '__main__':
    parser = setup_parser()
    args = parser.parse_args()

    if args.aws_credentials is None:
        # This allows aws roles to be used to create sessions.
        session = boto3.session.Session()
    else:
        session = create_session(args.aws_credentials)

    delete_func(session, args.name)