feat: make direct deployments the default (#12659)

* feat: make direct deployments the default

* docs: update docs to specify that direct deployments are the default
This commit is contained in:
Max Marze 2024-07-02 15:21:51 -04:00 committed by GitHub
parent e0d6a8acbb
commit d35327ea36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 12 deletions

View File

@ -44,16 +44,14 @@ The Serverless Framework translates all syntax in `serverless.yml` to a single A
### Deployment method
Since Serverless Framework v3, deployments are done using [CloudFormation change sets](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-changesets.html). It is possible to use [CloudFormation direct deployments](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-direct.html) instead.
Since Serverless Framework v4, deployments are by default done using CloudFormation direct deployments](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-direct.html). This is the recommended approach for most users.
Direct deployments **are faster** and have no downsides (unless you specifically use the generated change sets). They will become the default in Serverless Framework 4.
You are encouraged to enable direct deployments via the `deploymentMethod` option:
If you want to instead use [CloudFormation change sets](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-changesets.html), you can enable it via the `deploymentMethod` option:
```
provider:
name: aws
deploymentMethod: direct
deploymentMethod: changesets
```
### Tips

View File

@ -120,7 +120,7 @@ provider:
# CloudFormation tags to apply to the stack. Optional.
stackTags:
key: value
# Method used for CloudFormation deployments: 'changesets' or 'direct'. Optional. (default: changesets)
# Method used for CloudFormation deployments: 'changesets' or 'direct'. Optional. (default: direct)
# See https://www.serverless.com/framework/docs/providers/aws/guide/deploying#deployment-method
deploymentMethod: direct
# List of existing Amazon SNS topics in the same region where notifications about stack events are sent. Optional.

View File

@ -14,7 +14,10 @@ export default {
const stackName = this.provider.naming.getStackName()
let monitorCfData
if (this.serverless.service.provider.deploymentMethod === 'direct') {
if (
!this.serverless.service.provider.deploymentMethod ||
this.serverless.service.provider.deploymentMethod === 'direct'
) {
const params = this.getCreateStackParams({
templateBody:
this.serverless.service.provider.coreCloudFormationTemplate,

View File

@ -120,7 +120,10 @@ export default {
let monitorCfData
if (this.serverless.service.provider.deploymentMethod === 'direct') {
if (
!this.serverless.service.provider.deploymentMethod ||
this.serverless.service.provider.deploymentMethod === 'direct'
) {
const params = this.getUpdateStackParams({ templateBody })
monitorCfData = await this.provider.request(
@ -129,6 +132,7 @@ export default {
params,
)
} else {
// Change-set based deployment
const createChangeSetParams = this.getCreateChangeSetParams({
changeSetType: 'UPDATE',
templateBody,

View File

@ -19,7 +19,10 @@ export default {
const templateUrl = `https://${s3Endpoint}/${this.bucketName}/${this.serverless.service.package.artifactDirectoryName}/${compiledTemplateFileName}`
let monitorCfData
if (this.serverless.service.provider.deploymentMethod === 'direct') {
if (
!this.serverless.service.provider.deploymentMethod ||
this.serverless.service.provider.deploymentMethod === 'direct'
) {
const params = this.getCreateStackParams({
templateUrl,
})
@ -30,6 +33,7 @@ export default {
params,
)
} else {
// Change-set based deployment
const changeSetName = this.provider.naming.getStackChangeSetName()
const createChangeSetParams = this.getCreateChangeSetParams({
@ -88,7 +92,10 @@ export default {
const stackName = this.provider.naming.getStackName()
let monitorCfData
if (this.serverless.service.provider.deploymentMethod === 'direct') {
if (
!this.serverless.service.provider.deploymentMethod ||
this.serverless.service.provider.deploymentMethod === 'direct'
) {
const params = this.getUpdateStackParams({ templateUrl })
try {
@ -104,6 +111,7 @@ export default {
throw e
}
} else {
// Change-set based deployment
const changeSetName = this.provider.naming.getStackChangeSetName()
const createChangeSetParams = this.getCreateChangeSetParams({
@ -162,8 +170,7 @@ export default {
// as it might reference resources newly added in that change set.
// Applied only for ChangeSet deployments which is a default method
if (
(!this.serverless.service.provider.deploymentMethod ||
this.serverless.service.provider.deploymentMethod === 'changesets') &&
this.serverless.service.provider.deploymentMethod === 'changesets' &&
this.serverless.service.provider.stackPolicy &&
Object.keys(this.serverless.service.provider.stackPolicy).length
) {