Skip to content

Commit

Permalink
Merge pull request #2027 from updraft-com/master
Browse files Browse the repository at this point in the history
Lambda Layers & Cognito support
  • Loading branch information
jneves authored Feb 29, 2020
2 parents e9d902e + f297a0f commit 379c0bf
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,7 @@ to change Zappa's behavior. Use these at your own risk!
"keep_warm_expression": "rate(4 minutes)", // How often to execute the keep-warm, in cron and rate format. Default 4 minutes.
"lambda_description": "Your Description", // However you want to describe your project for the AWS console. Default "Zappa Deployment".
"lambda_handler": "your_custom_handler", // The name of Lambda handler. Default: handler.lambda_handler
"layers": ["arn:aws:lambda:<region>:<account_id>:layer:<layer_name>:<layer_version>"], // optional lambda layers
"lambda_concurrency": 10, // Sets the maximum number of simultaneous executions for a function, and reserves capacity for that concurrency level. Default is None.
"lets_encrypt_key": "s3://your-bucket/account.key", // Let's Encrypt account key path. Can either be an S3 path or a local file path.
"log_level": "DEBUG", // Set the Zappa log level. Can be one of CRITICAL, ERROR, WARNING, INFO and DEBUG. Default: DEBUG
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
{
"status_code": 200,
"data": {
"UserPool": {
"Id": "us-east-1_9jUv74DH8",
"Name": "Zappa-Test",
"Policies": {
"PasswordPolicy": {
"MinimumLength": 8,
"RequireUppercase": true,
"RequireLowercase": true,
"RequireNumbers": true,
"RequireSymbols": true,
"TemporaryPasswordValidityDays": 7
}
},
"LambdaConfig": {
"PreSignUp": "arn:aws:lambda:us-east-1:12345:function:Zappa-Trigger-Test"
},
"LastModifiedDate": {
"__class__": "datetime",
"year": 2017,
"month": 11,
"day": 27,
"hour": 11,
"minute": 23,
"second": 34,
"microsecond": 969000
},
"CreationDate": {
"__class__": "datetime",
"year": 2017,
"month": 11,
"day": 27,
"hour": 11,
"minute": 15,
"second": 36,
"microsecond": 195000
},
"SchemaAttributes": [
{
"Name": "sub",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": false,
"Required": true,
"StringAttributeConstraints": {
"MinLength": "1",
"MaxLength": "2048"
}
},
{
"Name": "name",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"StringAttributeConstraints": {
"MinLength": "0",
"MaxLength": "2048"
}
},
{
"Name": "given_name",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"StringAttributeConstraints": {
"MinLength": "0",
"MaxLength": "2048"
}
},
{
"Name": "family_name",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"StringAttributeConstraints": {
"MinLength": "0",
"MaxLength": "2048"
}
},
{
"Name": "middle_name",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"StringAttributeConstraints": {
"MinLength": "0",
"MaxLength": "2048"
}
},
{
"Name": "nickname",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"StringAttributeConstraints": {
"MinLength": "0",
"MaxLength": "2048"
}
},
{
"Name": "preferred_username",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"StringAttributeConstraints": {
"MinLength": "0",
"MaxLength": "2048"
}
},
{
"Name": "profile",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"StringAttributeConstraints": {
"MinLength": "0",
"MaxLength": "2048"
}
},
{
"Name": "picture",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"StringAttributeConstraints": {
"MinLength": "0",
"MaxLength": "2048"
}
},
{
"Name": "website",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"StringAttributeConstraints": {
"MinLength": "0",
"MaxLength": "2048"
}
},
{
"Name": "email",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": true,
"StringAttributeConstraints": {
"MinLength": "0",
"MaxLength": "2048"
}
},
{
"Name": "email_verified",
"AttributeDataType": "Boolean",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false
},
{
"Name": "gender",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"StringAttributeConstraints": {
"MinLength": "0",
"MaxLength": "2048"
}
},
{
"Name": "birthdate",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"StringAttributeConstraints": {
"MinLength": "10",
"MaxLength": "10"
}
},
{
"Name": "zoneinfo",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"StringAttributeConstraints": {
"MinLength": "0",
"MaxLength": "2048"
}
},
{
"Name": "locale",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"StringAttributeConstraints": {
"MinLength": "0",
"MaxLength": "2048"
}
},
{
"Name": "phone_number",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"StringAttributeConstraints": {
"MinLength": "0",
"MaxLength": "2048"
}
},
{
"Name": "phone_number_verified",
"AttributeDataType": "Boolean",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false
},
{
"Name": "address",
"AttributeDataType": "String",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"StringAttributeConstraints": {
"MinLength": "0",
"MaxLength": "2048"
}
},
{
"Name": "updated_at",
"AttributeDataType": "Number",
"DeveloperOnlyAttribute": false,
"Mutable": true,
"Required": false,
"NumberAttributeConstraints": {
"MinValue": "0"
}
}
],
"AutoVerifiedAttributes": [
"email"
],
"VerificationMessageTemplate": {
"DefaultEmailOption": "CONFIRM_WITH_CODE"
},
"MfaConfiguration": "OFF",
"EstimatedNumberOfUsers": 0,
"EmailConfiguration": {},
"UserPoolTags": {},
"AdminCreateUserConfig": {
"AllowAdminCreateUserOnly": false
},
"LambdaConfig": [
{"PreSignUp": "arn:aws:lambda:us-east-1:12345:function:Zappa-Trigger-Test"}
]
},
"ResponseMetadata": {
"RequestId": "ada5049e-d365-11e7-9a5a-2b0966933efa",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"content-type": "application/x-amz-json-1.1",
"date": "Mon, 27 Nov 2017 11:25:31 GMT",
"x-amzn-requestid": "ada5049e-d365-11e7-9a5a-2b0966933efa",
"content-length": "4132",
"connection": "keep-alive"
},
"RetryAttempts": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"status_code": 200,
"data": {
"ResponseMetadata": {
"RequestId": "adc3afdf-d365-11e7-b51f-abb88dfb5619",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"content-type": "application/x-amz-json-1.1",
"date": "Mon, 27 Nov 2017 11:25:32 GMT",
"x-amzn-requestid": "adc3afdf-d365-11e7-b51f-abb88dfb5619",
"content-length": "2",
"connection": "keep-alive"
},
"RetryAttempts": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"status_code": 201,
"data": {
"ResponseMetadata": {
"RequestId": "ae983eab-d365-11e7-ba13-8135763ed363",
"HTTPStatusCode": 201,
"HTTPHeaders": {
"date": "Mon, 27 Nov 2017 11:25:33 GMT",
"content-type": "application/json",
"content-length": "361",
"connection": "keep-alive",
"x-amzn-requestid": "ae983eab-d365-11e7-ba13-8135763ed363"
},
"RetryAttempts": 0
},
"Statement": "{\"Sid\":\"9UFS02MW\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"cognito-idp.amazonaws.com\"},\"Action\":\"lambda:InvokeFunction\",\"Resource\":\"arn:aws:lambda:us-east-1:12345:function:Zappa-Trigger-Test\",\"Condition\":{\"ArnLike\":{\"AWS:SourceArn\":\"arn:aws:cognito-idp:us-east-1:12345:userpool/us-east-1_9jUv74DH8\"}}}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"status_code": 200,
"data": {
"UserId": "RANDOMSTRING12314",
"Account": "12345",
"Arn": "arn:aws:iam::12345:user/test",
"ResponseMetadata": {
"RequestId": "ae5ff039-d365-11e7-ba9b-9d9eb3cc14f8",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"x-amzn-requestid": "ae5ff039-d365-11e7-ba9b-9d9eb3cc14f8",
"content-type": "text/xml",
"content-length": "401",
"date": "Mon, 27 Nov 2017 11:25:32 GMT"
},
"RetryAttempts": 0
}
}
}
15 changes: 15 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,21 @@ def test_update_aws_env_vars(self):
self.assertEqual(mock_client.update_function_configuration.call_args[1]["Environment"],
{"Variables": end_result_should_be})


def test_update_layers(self):
z = Zappa()
z.credentials_arn = object()

with mock.patch.object(z, "lambda_client") as mock_client:
mock_client.get_function_configuration.return_value = {}
z.update_lambda_configuration("test", "test", "test", layers=["Layer1", "Layer2"])
self.assertEqual(mock_client.update_function_configuration.call_args[1]["Layers"], ["Layer1", "Layer2"])
with mock.patch.object(z, "lambda_client") as mock_client:
mock_client.get_function_configuration.return_value = {}
z.update_lambda_configuration("test", "test", "test")
self.assertEqual(mock_client.update_function_configuration.call_args[1]["Layers"], [])


def test_update_empty_aws_env_hash(self):
z = Zappa()
z.credentials_arn = object()
Expand Down
5 changes: 4 additions & 1 deletion tests/tests_placebo.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,10 @@ def test_cli_cognito_triggers(self, session):
zappa_cli.lambda_arn = 'arn:aws:lambda:us-east-1:12345:function:Zappa-Trigger-Test'
zappa_cli.update_cognito_triggers()


@placebo_session
def test_cognito_trigger_existing_UnusedAccountValidityDays(self, session):
z = Zappa(session)
z.update_cognito('Zappa-Trigger-Test', 'us-east-1_9jUv74DH8', {'PreSignUp': 'test.tasks.pre_signup'}, 'arn:aws:lambda:us-east-1:12345:function:Zappa-Trigger-Test')


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 379c0bf

Please sign in to comment.