Skip to content

Commit

Permalink
Merge pull request #698 from aws/dev
Browse files Browse the repository at this point in the history
chore: release 1.3
  • Loading branch information
96malhar authored Sep 8, 2022
2 parents 66fb1e3 + e873dae commit 3bc852c
Show file tree
Hide file tree
Showing 41 changed files with 1,059 additions and 90 deletions.
12 changes: 9 additions & 3 deletions THIRD_PARTY_LICENSES
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
** Amazon.JSII.Runtime; version 1.54.0 -- https://www.nuget.org/packages/Amazon.JSII.Runtime
** AWSSDK.CloudControlApi; version 3.7.2 -- https://www.nuget.org/packages/AWSSDK.CloudControlApi/
** AWSSDK.SimpleSystemsManagement; version 3.7.16 -- https://www.nuget.org/packages/AWSSDK.SimpleSystemsManagement/
** AWSSDK.SSO; version 3.7.0.201 -- https://www.nuget.org/packages/AWSSDK.SSO
** AWSSDK.SSOOIDC; version 3.7.1.4 -- https://www.nuget.org/packages/AWSSDK.SSOOIDC

Apache License
Version 2.0, January 2004
Expand Down Expand Up @@ -253,6 +255,10 @@ limitations under the License.
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* For AWSSDK.SimpleSystemsManagement see also this required NOTICE:
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* For AWSSDK.SSO see also this required NOTICE:
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* For AWSSDK.SSOOIDC see also this required NOTICE:
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

------

Expand Down Expand Up @@ -334,8 +340,6 @@ Copyright (c) 2016 .NET Foundation
Copyright (c) 2016 .NET Foundation
** Microsoft.Extensions.Configuration.Json; version 3.1.7 -- https://www.nuget.org/packages/Microsoft.Bcl.AsyncInterhttps://www.nuget.org/packages/Microsoft.Extensions.Configuration.Jsonfaces
Copyright (c) .NET Foundation and Contributors
** System.Text.Json; version 6.0.4 -- https://www.nuget.org/packages/System.Text.Json
Copyright (c) .NET Foundation and Contributors
** Microsoft.Extensions.DependencyInjection; version 6.0.0 -- https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection
Copyright (c) .NET Foundation and Contributors
** Microsoft.Extensions.DependencyInjection.Abstractions; version 6.0.0 -- https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection.Abstractions
Expand All @@ -344,7 +348,9 @@ Copyright (c) .NET Foundation and Contributors
Copyright (c) .NET Foundation and Contributors
** Microsoft.OpenApi; version 1.2.3 -- https://www.nuget.org/packages/Microsoft.OpenApi/
Copyright (c) Microsoft Corporation.

** System.Text.Json; version 6.0.4 -- https://www.nuget.org/packages/System.Text.Json
Copyright (c) .NET Foundation and Contributors

All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
65 changes: 59 additions & 6 deletions site/content/docs/cicd.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,68 @@ To turn off the interactive features, use the `-s (--silent)` switch. This will

dotnet aws deploy --silent

### Creating a deployment setting file
### Creating a deployment settings file

To specify the services to deploy and their configurations for your environment, you need to create deployment settings file. The deployment settings file is a JSON configuration file that contains all of the settings that the deployment tool uses to drive the experience. Here is the [JSON file definition](https://github.com/aws/aws-dotnet-deploy/tree/main/src/AWS.Deploy.Recipes/RecipeDefinitions).
You can persist the deployment configuration to a JSON file using the `--save-settings <SETTINGS_FILE_PATH)>` switch. This JSON file can be version controlled and plugged into your CI/CD system for future deployments.

Storing deployment settings in a JSON file also allows those settings to be version controlled.
**Note** - The `--save-settings` switch will only persist settings that have been modified (which means they hold a non-default value). To persist all settings use the `--save-all-settings` switch.

```
dotnet aws deploy --project-path <PROJECT_PATH> [--save-settings|--save-all-settings] <SETTINGS_FILE_PATH>
```

**Note** - The `SETTINGS_FILE_PATH` can be an absolute path or relative to the `PROJECT_PATH`.

Here's an example of a web application with the following directory structure:

MyWebApplication/
┣ MyClassLibrary/
┃ ┣ Class1.cs
┃ ┗ MyClassLibrary.csproj
┣ MyWebApplication/
┃ ┣ Controllers/
┃ ┃ ┗ WeatherForecastController.cs
┃ ┣ appsettings.Development.json
┃ ┣ appsettings.json
┃ ┣ Dockerfile
┃ ┣ MyWebApplication.csproj
┃ ┣ Program.cs
┃ ┣ WeatherForecast.cs
┗ MyWebApplication.sln

To perform a deployment and also persist the deployment configuration to a JSON file, use the following command:
```
dotnet aws deploy --project-path MyWebApplication/MyWebApplication/MyWebApplication.csproj --save-settings deploymentsettings.json
```

This will create a JSON file at `MyWebApplication/MyWebApplication/deploymentsettings.json` with the following structure:
```
{
"AWSProfile": <AWS_PROFILE>
"AWSRegion": <AWS_REGION>,
"ApplicationName": <APPLICATION_NAME>,
"RecipeId": <RECIPE_ID>
"Settings": <JSON_BLOB>
}
```
* _**AWSProfile**_: The name of the AWS profile that was used during deployment.

* _**AWSRegion**_: The name of the AWS region where the deployed application is hosted.

* _**ApplicationName**_: The name that is used to identify your cloud application within AWS. If the application is deployed via AWS CDK, then this name points to the CloudFormation stack.

* _**RecipeId**_: The recipe identifier that was used to deploy your application to AWS.

* _**Settings**_: This is a JSON blob that stores the values of all available settings that can be tweaked to adjust the deployment configuration.

### Invoking from CI/CD

The `--apply` switch on deploy command allows you to specify a deployment settings file.
The `--apply` switch on the deploy command allows you to specify a deployment settings file.

Deployment settings file path is always relative to the `--project-path`. Here's an example of a web application with the following directory structure:
```
dotnet aws deploy --project-path <PROJECT_PATH> --apply <SETTINGS_FILE_PATH>
```

MyWebApplication/
┣ MyClassLibrary/
Expand All @@ -36,7 +87,9 @@ Deployment settings file path is always relative to the `--project-path`. Here's
┃ ┗ WeatherForecast.cs
┗ MyWebApplication.sln

To deploy the application with above directory structure in CI/CD pipeline without any prompts, use the following command:
To deploy the application with the above directory structure in CI/CD pipeline without any prompts, use the following command:

dotnet aws deploy --silent --project-path MyWebApplication/MyWebApplication/MyWebApplication.csproj --apply deploymentsettings.json



2 changes: 1 addition & 1 deletion site/content/docs/commands/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
dotnet aws deploy - Inspect, build, and deploy the .NET project to AWS using the chosen AWS compute.

### Synopsis
dotnet aws deploy [-d|—-diagnostics] [-s|--silent] [--profile <PROFILE>] [--region <REGION>] [--project-path <PROJECT-PATH>] [--application-name <CLOUD-APPLICATION-NAME>] [--apply <PATH-TO-DEPLOYMENT-SETTINGS>] [--deployment-project <CDK-DEPLOYMENT-PROJECT-PATH>] [-?|-h|--help]
dotnet aws deploy [-d|—-diagnostics] [-s|--silent] [--profile <PROFILE>] [--region <REGION>] [--project-path <PROJECT-PATH>] [[--save-settings|--save-all-settings] <SETTINGS-FILE-PATH>] [--application-name <CLOUD-APPLICATION-NAME>] [--apply <PATH-TO-DEPLOYMENT-SETTINGS>] [--deployment-project <CDK-DEPLOYMENT-PROJECT-PATH>] [-?|-h|--help]

### Description
Inspects the project and recommends AWS compute that is most suited to the type of deployed application. Then builds the project, generates a deployment CDK project to provision the required infrastructure, and deploys the .NET project to AWS using the chosen AWS compute.
Expand Down
8 changes: 4 additions & 4 deletions site/content/docs/getting-started/setup-creds.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ The following are some examples of the typical permissions that are required.
|Command| Task | Recommended AWS Managed Policies |
| --- | --- |--- |
|deploy | Deploying to Amazon ECS | AWSCloudFormationFullAccess, AmazonECS_FullAccess, AmazonEC2ContainerRegistryFullAccess, IAMFullAccess |
|deploy | Deploying to AWS App Runner| AWSCloudFormationFullAccess, AWSAppRunnerFullAccess, AmazonEC2ContainerRegistryFullAccess, IAMFullAccess|
|deploy | Deploying to Elastic Beanstalk (deploy) | AWSCloudFormationFullAccess, AdministratorAccess-AWSElasticBeanstalk', AmazonS3FullAccess (*required to upload the application bundle*), IAMFullAccess |
|deploy | Hosting WebAssembly Blazor App in S3 & CloudFront | AmazonS3FullAccess, CloudFrontFullAccess, IAMFullAccess, AWSLambda_FullAccess (*required to copy from CDKBootstrap bucket to S3 bucket*)|
|deploy | Deploying to Amazon ECS | AWSCloudFormationFullAccess, AmazonECS_FullAccess, AmazonEC2ContainerRegistryFullAccess, AmazonSSMFullAccess, IAMFullAccess |
|deploy | Deploying to AWS App Runner| AWSCloudFormationFullAccess, AWSAppRunnerFullAccess, AmazonEC2ContainerRegistryFullAccess, AmazonSSMFullAccess, IAMFullAccess|
|deploy | Deploying to Elastic Beanstalk (deploy) | AWSCloudFormationFullAccess, AdministratorAccess-AWSElasticBeanstalk, AmazonSSMFullAccess, AmazonS3FullAccess (*required to upload the application bundle*), IAMFullAccess |
|deploy | Hosting WebAssembly Blazor App in S3 & CloudFront | AmazonS3FullAccess, CloudFrontFullAccess, IAMFullAccess, AmazonSSMFullAccess, AWSLambda_FullAccess (*required to copy from CDKBootstrap bucket to S3 bucket*)|
| list-deployments | List CF stacks| AWSCloudFormationReadOnlyAccess |
| delete-deployment | Delete a CF stack | AWSCloudFormationFullAccess + permissions for resources being deleted |

Expand Down
10 changes: 10 additions & 0 deletions site/content/troubleshooting-guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,13 @@ StagingBucket cdk-hnb659fds-assets-123456789101-us-west-2 already exists
```

**Resolution**: Open the AWS Console, go to S3 service, and manually delete the 'CDKToolkit' S3 bucket. Once the bucket is deleted, go ahead and deploy your application.

## MemorySize Constraint for Blazor WebAssembly
When attempting to deploy using the Blazor WebAssembly App recipe, you may see a deployment failure such as:
```
Resource handler returned message: "'MemorySize' value failed to satisfy constraint: Member must have value less than or equal to 3008
```

**Why this is happening:** The [BucketDeployment](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3_deployment.BucketDeployment.html) CDK Construct used to deploy the Blazor recipe uses an AWS Lambda function to replicate the application files from the CDK bucket to the deployment bucket. In some versions of the deploy tool the default memory limit for this Lambda function exceeded the 3008MB quota placed on new AWS accounts.

**Resolution:** See [Lambda: Concurrency and memory quotas](https://docs.aws.amazon.com/lambda/latest/dg/troubleshooting-deployment.html#troubleshooting-deployment-quotas) for how to request a quota increase.
2 changes: 2 additions & 0 deletions src/AWS.Deploy.CLI/AWS.Deploy.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.2.25" />
<PackageReference Include="AWSSDK.CloudFormation" Version="3.7.7.14" />
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.1.35" />
<PackageReference Include="AWSSDK.SSO" Version="3.7.0.201" />
<PackageReference Include="AWSSDK.SSOOIDC" Version="3.7.1.4" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.1.2" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.1.2" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
Expand Down
8 changes: 7 additions & 1 deletion src/AWS.Deploy.CLI/Commands/CommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class CommandFactory : ICommandFactory
private static readonly Option<string> _optionOutputDirectory = new(new[] { "-o", "--output" }, "Directory path in which the CDK deployment project will be saved.");
private static readonly Option<string> _optionProjectDisplayName = new(new[] { "--project-display-name" }, "The name of the deployment project that will be displayed in the list of available deployment options.");
private static readonly Option<string> _optionDeploymentProject = new(new[] { "--deployment-project" }, "The absolute or relative path of the CDK project that will be used for deployment");
private static readonly Option<string> _optionSaveSettings = new(new[] { "--save-settings" }, "The absolute or the relative JSON file path where the deployment settings will be saved. Only the settings modified by the user will be persisted");
private static readonly Option<string> _optionSaveAllSettings = new(new[] { "--save-all-settings" }, "The absolute or the relative JSON file path where the deployment settings will be saved. All deployment settings will be persisted");
private static readonly object s_root_command_lock = new();
private static readonly object s_child_command_lock = new();

Expand Down Expand Up @@ -180,6 +182,8 @@ private Command BuildDeployCommand()
deployCommand.Add(_optionDiagnosticLogging);
deployCommand.Add(_optionDisableInteractive);
deployCommand.Add(_optionDeploymentProject);
deployCommand.Add(_optionSaveSettings);
deployCommand.Add(_optionSaveAllSettings);
}

deployCommand.Handler = CommandHandler.Create(async (DeployCommandHandlerInput input) =>
Expand Down Expand Up @@ -252,7 +256,9 @@ private Command BuildDeployCommand()
deploymentProjectPath = Path.GetFullPath(deploymentProjectPath, targetApplicationDirectoryPath);
}
await deploy.ExecuteAsync(input.ApplicationName ?? string.Empty, deploymentProjectPath, deploymentSettings);
var saveSettingsConfig = Helpers.GetSaveSettingsConfiguration(input.SaveSettings, input.SaveAllSettings, targetApplicationDirectoryPath, _fileManager);
await deploy.ExecuteAsync(input.ApplicationName ?? string.Empty, deploymentProjectPath, saveSettingsConfig, deploymentSettings);
return CommandReturnCodes.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,54 @@ namespace AWS.Deploy.CLI.Commands.CommandHandlerInput
{
public class DeployCommandHandlerInput
{
/// <summary>
/// AWS credential profile used to make calls to AWS.
/// </summary>
public string? Profile { get; set; }

/// <summary>
/// AWS region to deploy the application to. For example, us-west-2.
/// </summary>
public string? Region { get; set; }

/// <summary>
/// Path to the project to deploy.
/// </summary>
public string? ProjectPath { get; set; }

/// <summary>
/// Name of the cloud application.
/// </summary>
public string? ApplicationName { get; set; }

/// <summary>
/// Path to the deployment settings file to be applied.
/// </summary>
public string? Apply { get; set; }

/// <summary>
/// Flag to enable diagnostic output.
/// </summary>
public bool Diagnostics { get; set; }

/// <summary>
/// Flag to disable interactivity to execute commands without any prompts.
/// </summary>
public bool Silent { get; set; }

/// <summary>
/// The absolute or relative path of the CDK project that will be used for deployment.
/// </summary>
public string? DeploymentProject { get; set; }

/// <summary>
/// The absolute or the relative JSON file path where the deployment settings will be saved. Only the settings modified by the user are persisted.
/// </summary>
public string? SaveSettings { get; set; }

/// <summary>
/// The absolute or the relative JSON file path where the deployment settings will be saved. All deployment settings are persisted.
/// </summary>
public string? SaveAllSettings { get; set; }
}
}
28 changes: 25 additions & 3 deletions src/AWS.Deploy.CLI/Commands/DeployCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public DeployCommand(
_deploymentSettingsHandler = deploymentSettingsHandler;
}

public async Task ExecuteAsync(string applicationName, string deploymentProjectPath, DeploymentSettings? deploymentSettings = null)
public async Task ExecuteAsync(string applicationName, string deploymentProjectPath, SaveSettingsConfiguration saveSettingsConfig, DeploymentSettings? deploymentSettings = null)
{
var (orchestrator, selectedRecommendation, cloudApplication) = await InitializeDeployment(applicationName, deploymentSettings, deploymentProjectPath);

Expand All @@ -130,6 +130,12 @@ public async Task ExecuteAsync(string applicationName, string deploymentProjectP

await CreateDeploymentBundle(orchestrator, selectedRecommendation, cloudApplication);

if (saveSettingsConfig.SettingsType != SaveSettingsType.None)
{
await _deploymentSettingsHandler.SaveSettings(saveSettingsConfig, selectedRecommendation, cloudApplication, _session);
_toolInteractiveService.WriteLine($"{Environment.NewLine}Successfully saved the deployment settings at {saveSettingsConfig.FilePath}");
}

await orchestrator.DeployRecommendation(cloudApplication, selectedRecommendation);

var displayedResources = await _displayedResourcesHandler.GetDeploymentOutputs(cloudApplication, selectedRecommendation);
Expand Down Expand Up @@ -193,11 +199,27 @@ private void DisplayOutputResources(List<DisplayedResourceItem> displayedResourc
cloudApplicationName = deploymentSettings?.ApplicationName ?? string.Empty;

// Prompt the user with a choice to re-deploy to existing targets or deploy to a new cloud application.
if (string.IsNullOrEmpty(cloudApplicationName))
// This prompt is NOT needed if the user is just pushing the docker image to ECR.
if (string.IsNullOrEmpty(cloudApplicationName) && !string.Equals(deploymentSettings?.RecipeId, Constants.RecipeIdentifier.PUSH_TO_ECR_RECIPE_ID))
cloudApplicationName = AskForCloudApplicationNameFromDeployedApplications(compatibleApplications);

// Find existing application with the same CloudApplication name.
var deployedApplication = allDeployedApplications.FirstOrDefault(x => string.Equals(x.Name, cloudApplicationName));
CloudApplication? deployedApplication = null;
if (!string.IsNullOrEmpty(deploymentSettings?.RecipeId))
{
// if the recommendation is specified via a config file then find the deployed application by matching the deployment type along with the cloudApplicationName
var recommendation = recommendations.FirstOrDefault(x => string.Equals(x.Recipe.Id, deploymentSettings.RecipeId));
if (recommendation == null)
{
var errorMsg = "The recipe ID specified in the deployment settings file does not match any compatible deployment recipes.";
throw new InvalidDeploymentSettingsException(DeployToolErrorCode.DeploymentConfigurationNeedsAdjusting, errorMsg);
}
deployedApplication = allDeployedApplications.FirstOrDefault(x => string.Equals(x.Name, cloudApplicationName) && x.DeploymentType == recommendation.Recipe.DeploymentType);
}
else
{
deployedApplication = allDeployedApplications.FirstOrDefault(x => string.Equals(x.Name, cloudApplicationName));
}

Recommendation? selectedRecommendation = null;
if (deployedApplication != null)
Expand Down
Loading

0 comments on commit 3bc852c

Please sign in to comment.