diff --git a/README.md b/README.md index ab3de53..bb1a00a 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ This section explains how to deploy an AWS Lambda function to AWS API Gateway us 1. Finally, run MultiTool Canary, pointing to a pre-built zip: ```bash - $ canary deploy deploy --aws-apig-name ${MY_APIGATEWAY_NAME} --aws-apig-stage ${MY_APIGATEWAY_STAGE} --aws-lambda ${MY_LAMBDA_NAME} ./my-release.zip + $ canary deploy deploy --aws-apig-name ${MY_APIGATEWAY_NAME} --aws-apig-stage ${MY_APIGATEWAY_STAGE} --aws-lambda ${MY_LAMBDA_NAME} --aws-resource-path ${MY_RESOURCE_NAME} --aws-resource-method ${MY_RESOURCE_METHOD} ./my-release.zip ``` MultiTool Canary will upload the function to AWS, cut a canary release, and monitor it, progresssingly ramping up traffic as it gains confidence in the deployment. MultiTool Canary scans your CloudWatch metrics to see how your canary application is performing relative to the baseline, and models release confidence based on how they differ. diff --git a/guides/quickstart/quickstart.md b/guides/quickstart/quickstart.md index d7d03e7..a12bbba 100644 --- a/guides/quickstart/quickstart.md +++ b/guides/quickstart/quickstart.md @@ -146,7 +146,7 @@ Start MultiTool Canary to upload your new lambda version and start monitoring tr In order to see MultiTool Canary in action, we'll need to simulate some traffic to our API endpoint. We can do that autoamtically with a tool like [Bombardier](https://github.com/codesenberg/bombardier) or manually with an API Client like [Bruno](https://www.usebruno.com/) or [Postman](https://www.postman.com/) ```bash -$ canary deploy --aws-apig-name ${MY_APIGATEWAY_NAME} --aws-apig-stage ${MY_APIGATEWAY_STAGE} --aws-lambda ${MY_LAMBDA_NAME} out.zip +$ canary deploy --aws-apig-name ${MY_APIGATEWAY_NAME} --aws-apig-stage ${MY_APIGATEWAY_STAGE} --aws-lambda ${MY_LAMBDA_NAME} --aws-resource-name ${MY_RESOURCE_NAME} --aws-resource-method ${MY_RESOURCE_METHOD} out.zip $ watch -n 30 bombardier -c 5 -n 50 ${MY_URL} | grep "HTTP codes:" -A 1 | tail -n +2 ``` diff --git a/src/adapters/ingresses/apig.rs b/src/adapters/ingresses/apig.rs index b048217..aaa2dc7 100644 --- a/src/adapters/ingresses/apig.rs +++ b/src/adapters/ingresses/apig.rs @@ -26,6 +26,8 @@ pub struct AwsApiGateway { stage_name: String, lambda_name: String, aws_region: String, + resource_path: String, + resource_method: String, } impl AwsApiGateway { @@ -35,6 +37,8 @@ impl AwsApiGateway { gateway_name: &str, stage_name: &str, lambda_name: &str, + resource_path: &str, + resource_method: &str, ) -> Result { let artifact = read_file(artifact_path).await?; // Now, configure the AWS SDKs. @@ -55,6 +59,8 @@ impl AwsApiGateway { .region() .ok_or(miette!("Couldn't get AWS Region"))? .to_string(), + resource_path: resource_path.to_owned(), + resource_method: resource_method.to_owned(), }) } @@ -169,12 +175,19 @@ impl Ingress for AwsApiGateway { )) .build(); + let resource = self + .get_resource_id_by_name(api_id, &self.resource_path) + .await?; + let resource_id = resource + .id() + .ok_or(miette!("Couldn't get ID of Resource"))?; + // Next, we need to update our API Gateway to point at our new lambda version self.apig_client .update_integration() .rest_api_id(api_id) - .resource_id("ws63qm") // TODO: fix this - .http_method("GET") + .resource_id(resource_id) + .http_method(&self.resource_method) .patch_operations(patch_op) .send() .await diff --git a/src/cmd/deploy.rs b/src/cmd/deploy.rs index 0e8623c..78f6f8d 100644 --- a/src/cmd/deploy.rs +++ b/src/cmd/deploy.rs @@ -11,6 +11,8 @@ pub struct Deploy { gateway_name: String, stage_name: String, lambda_name: String, + resource_path: String, + resource_method: String, } impl Deploy { @@ -23,6 +25,8 @@ impl Deploy { gateway_name: args.aws_apig_name, stage_name: args.aws_apig_stage, lambda_name: args.aws_lambda, + resource_path: args.aws_resource_path, + resource_method: args.aws_resource_method, } } @@ -36,6 +40,8 @@ impl Deploy { &self.gateway_name, &self.stage_name, &self.lambda_name, + &self.resource_path, + &self.resource_method, ) .await?; // • TODO: Create the ingress, passing in the path to the deployment artifact. diff --git a/src/config/deploy/mod.rs b/src/config/deploy/mod.rs index bd42abc..4133ecf 100644 --- a/src/config/deploy/mod.rs +++ b/src/config/deploy/mod.rs @@ -17,4 +17,10 @@ pub struct DeploySubcommand { /// The name of the AWS Lambda function to update. #[arg(long, env = "MULTI_AWS_LAMBDA")] pub aws_lambda: String, + /// The path of the AWS API Gateway Resource, including the leading '/' + #[arg(long, env = "MULTI_AWS_RESOURCE_PATH")] + pub aws_resource_path: String, + /// The HTTP method of the AWS API Gateway Resource + #[arg(long, env = "MULTI_AWS_RESOURCE_METHOD")] + pub aws_resource_method: String, }