Skip to content

Commit

Permalink
Remove hard-coded resource path and method
Browse files Browse the repository at this point in the history
  • Loading branch information
EricGhildyal committed Dec 2, 2024
1 parent faae056 commit 7603784
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion guides/quickstart/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
17 changes: 15 additions & 2 deletions src/adapters/ingresses/apig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub struct AwsApiGateway {
stage_name: String,
lambda_name: String,
aws_region: String,
resource_path: String,
resource_method: String,
}

impl AwsApiGateway {
Expand All @@ -35,6 +37,8 @@ impl AwsApiGateway {
gateway_name: &str,
stage_name: &str,
lambda_name: &str,
resource_path: &str,
resource_method: &str,
) -> Result<Self> {
let artifact = read_file(artifact_path).await?;
// Now, configure the AWS SDKs.
Expand All @@ -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(),
})
}

Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/cmd/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub struct Deploy {
gateway_name: String,
stage_name: String,
lambda_name: String,
resource_path: String,
resource_method: String,
}

impl Deploy {
Expand All @@ -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,
}
}

Expand All @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/config/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

0 comments on commit 7603784

Please sign in to comment.