示例#1
0
    def test_create_lambda_function_no_variables_or_events(self):
        result = lambda_writer.create_lambda_function('HelloLambda',
                                                      'file.handler', 'uridir',
                                                      [], [], [], {})

        self.assertEqual(result['Type'], 'AWS::Serverless::Function')

        properties = result['Properties']

        self.assertEqual(properties['CodeUri'], 'uridir')
        self.assertEqual(properties['Handler'], 'file.handler')
        self.assertEqual(properties['Role']['Fn::GetAtt'],
                         ['HelloLambdaRole', 'Arn'])
        self.assertFalse('Events' in properties)
        self.assertFalse('Environment' in properties)
def _write_lambdas(lambdas: list, set_globals: bool, language: str,
                   existing_template: dict) -> dict:
    resources = dict()

    for l in lambdas:
        new_lambda = lambda_writer.create_lambda_function(
            l['name'], l['handler'], l['uri'], l['variables'], l['events'],
            l['api'], existing_template)

        if not set_globals:
            new_lambda = _set_non_global_properties(l['name'], new_lambda,
                                                    language,
                                                    existing_template)

        resources[l['name']] = new_lambda

    return resources
示例#3
0
    def test_create_lambda_function_api(self):
        result = lambda_writer.create_lambda_function('HelloLambda',
                                                      'file.handler', 'uridir',
                                                      [], [],
                                                      ['get', '/hello/world'],
                                                      {})

        self.assertEqual(result['Type'], 'AWS::Serverless::Function')

        properties = result['Properties']

        self.assertEqual(properties['CodeUri'], 'uridir')
        self.assertEqual(properties['Handler'], 'file.handler')
        self.assertEqual(properties['Events']['GET']['Type'], 'Api')
        self.assertEqual(properties['Events']['GET']['Properties']['Path'],
                         '/hello/world')
        self.assertEqual(properties['Events']['GET']['Properties']['Method'],
                         'get')
示例#4
0
    def test_create_lambda_function_with_rate_schedule_event(self):
        result = lambda_writer.create_lambda_function('HelloLambda',
                                                      'file.handler', 'uridir',
                                                      [], ['Schedule:2 hours'],
                                                      [], {})

        self.assertEqual(result['Type'], 'AWS::Serverless::Function')

        properties = result['Properties']

        self.assertEqual(properties['CodeUri'], 'uridir')
        self.assertEqual(properties['Handler'], 'file.handler')
        self.assertEqual(properties['Role']['Fn::GetAtt'],
                         ['HelloLambdaRole', 'Arn'])
        self.assertEqual(
            properties['Events']['HelloLambdaScheduleEvent']['Type'],
            'Schedule')
        self.assertEqual(
            properties['Events']['HelloLambdaScheduleEvent']['Properties']
            ['Schedule'], 'rate(2 hours)')
示例#5
0
    def test_create_lambda_function(self):
        result = lambda_writer.create_lambda_function('HelloLambda',
                                                      'file.handler', 'uridir',
                                                      ['BUCKET'], ['S3'], [],
                                                      {})

        self.assertEqual(result['Type'], 'AWS::Serverless::Function')

        properties = result['Properties']

        self.assertEqual(properties['CodeUri'], 'uridir')
        self.assertEqual(properties['Handler'], 'file.handler')
        self.assertEqual(properties['Role']['Fn::GetAtt'],
                         ['HelloLambdaRole', 'Arn'])
        self.assertEqual(properties['Environment']['Variables']['BUCKET'],
                         'Fill in value or delete if not needed')
        self.assertEqual(properties['Events']['HelloLambdaS3Event']['Type'],
                         'S3')
        self.assertEqual(
            properties['Events']['HelloLambdaS3Event']['Properties']['Bucket']
            ['Ref'], 'S3EventBucket')
        self.assertEqual(
            properties['Events']['HelloLambdaS3Event']['Properties']['Events'],
            's3:ObjectCreated:*')
示例#6
0
    def test_create_lambda_function_existing_value(self):
        first_resource = {
            'Type': 'AWS::Serverless::Function',
            'Properties': {
                'Environment': {
                    'Variables': {
                        'BUCKET': 'my-own-bucket-name'
                    }
                }
            }
        }
        existing_template_dict = {'Resources': {'First': first_resource}}

        result = lambda_writer.create_lambda_function('HelloLambda',
                                                      'file.handler', 'uridir',
                                                      ['BUCKET'], ['S3'], [],
                                                      existing_template_dict)

        self.assertEqual(result['Type'], 'AWS::Serverless::Function')

        properties = result['Properties']

        self.assertEqual(properties['CodeUri'], 'uridir')
        self.assertEqual(properties['Handler'], 'file.handler')
        self.assertEqual(properties['Role']['Fn::GetAtt'],
                         ['HelloLambdaRole', 'Arn'])
        self.assertEqual(properties['Environment']['Variables']['BUCKET'],
                         'my-own-bucket-name')
        self.assertEqual(properties['Events']['HelloLambdaS3Event']['Type'],
                         'S3')
        self.assertEqual(
            properties['Events']['HelloLambdaS3Event']['Properties']['Bucket']
            ['Ref'], 'S3EventBucket')
        self.assertEqual(
            properties['Events']['HelloLambdaS3Event']['Properties']['Events'],
            's3:ObjectCreated:*')