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

Update function_with_custom_code_deploy integration test case #2320

Merged
merged 2 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest.case import skipIf

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.helpers.resource import current_region_does_not_support, generate_suffix
from integration.config.service_names import CODE_DEPLOY

CODEDEPLOY_APPLICATION_LOGICAL_ID = "ServerlessDeploymentApplication"
Expand All @@ -16,15 +16,11 @@ def test_lambda_function_with_deployment_preference_uses_code_deploy(self):
self._verify_no_deployment_then_update_and_verify_deployment()

def test_lambda_function_with_custom_deployment_preference(self):
custom_deployment_config_name = "CustomLambdaDeploymentConfiguration"
# Want to delete / recreate custom deployment resource to make sure it exists and hasn't changed
if self._has_custom_deployment_configuration(custom_deployment_config_name):
self._delete_deployment_configuration(custom_deployment_config_name)
custom_deployment_config_name = "CustomLambdaDeploymentConfiguration" + generate_suffix()
parameters = [self.generate_parameter("DeployConfigName", custom_deployment_config_name)]

self._create_deployment_configuration(custom_deployment_config_name)

self.create_and_verify_stack("combination/function_with_custom_code_deploy")
self._verify_no_deployment_then_update_and_verify_deployment()
self.create_and_verify_stack("combination/function_with_custom_code_deploy", parameters)
self._verify_no_deployment_then_update_and_verify_deployment(parameters)

def test_use_default_manage_policy(self):
self.create_and_verify_stack("combination/function_with_deployment_default_role_managed_policy")
Expand Down Expand Up @@ -140,23 +136,6 @@ def _get_physical_resource_id(self, resource_type, logical_id):
)
return resources_with_this_id["PhysicalResourceId"]

def _has_custom_deployment_configuration(self, deployment_name):
result = self.client_provider.code_deploy_client.list_deployment_configs()["deploymentConfigsList"]
return deployment_name in result

def _delete_deployment_configuration(self, deployment_name):
self.client_provider.code_deploy_client.delete_deployment_config(deploymentConfigName=deployment_name)

def _create_deployment_configuration(self, deployment_name):
client = self.client_provider.code_deploy_client
traffic_routing_config = {
"type": "TimeBasedLinear",
"timeBasedLinear": {"linearPercentage": 50, "linearInterval": 1},
}
client.create_deployment_config(
deploymentConfigName=deployment_name, computePlatform="Lambda", trafficRoutingConfig=traffic_routing_config
)

def _get_deployment_group_configuration_name(self, deployment_group_name, application_name):
deployment_group = self.client_provider.code_deploy_client.get_deployment_group(
applicationName=application_name, deploymentGroupName=deployment_group_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
{ "LogicalResourceId":"MyLambdaFunctionVersion", "ResourceType":"AWS::Lambda::Version" },
{ "LogicalResourceId":"ServerlessDeploymentApplication", "ResourceType":"AWS::CodeDeploy::Application" },
{ "LogicalResourceId":"MyLambdaFunctionDeploymentGroup", "ResourceType":"AWS::CodeDeploy::DeploymentGroup" },
{ "LogicalResourceId":"DeploymentRole", "ResourceType":"AWS::IAM::Role" }
{ "LogicalResourceId":"DeploymentRole", "ResourceType":"AWS::IAM::Role" },
{ "LogicalResourceId":"CustomDeploymentConfig", "ResourceType":"AWS::CodeDeploy::DeploymentConfig" }
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Parameters:
DeployConfigName:
Type: String

# Just one function with a deployment preference
Resources:
MyLambdaFunction:
DependsOn: CustomDeploymentConfig
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: ${codeuri}
Expand All @@ -10,7 +15,8 @@ Resources:
AutoPublishAlias: Live

DeploymentPreference:
Type: CustomLambdaDeploymentConfiguration
Type:
Ref: CustomDeploymentConfig
Role:
Fn::GetAtt: [ DeploymentRole, Arn ]

Expand Down Expand Up @@ -43,3 +49,15 @@ Resources:
- "lambda:InvokeFunction"
- "s3:Get*"
- "sns:Publish"

CustomDeploymentConfig:
Type: AWS::CodeDeploy::DeploymentConfig
Properties:
DeploymentConfigName:
Ref: DeployConfigName
ComputePlatform: Lambda
TrafficRoutingConfig:
Type: TimeBasedLinear
TimeBasedLinear:
LinearInterval: 1
LinearPercentage: 50