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

Add stackName to plugin params #391

Merged
merged 3 commits into from
Jan 23, 2025
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
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

---

## [5.0.8] 2025-01-23

### Changed

- Added `stackName` property to Deploy plugin params
- Improved error handling during Lambda direct updates

---

## [5.0.7] 2024-04-30

### Fixed
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@aws-lite/s3": "^0.1.21",
"@aws-lite/ssm": "^0.2.3",
"chalk": "4.1.2",
"fs-extra": "~11.2.0",
"fs-extra": "~11.3.0",
"get-folder-size": "2.0.1",
"glob": "~10.3.12",
"mime-types": "~2.1.35",
Expand All @@ -61,11 +61,11 @@
"devDependencies": {
"@architect/eslint-config": "~3.0.0",
"cross-env": "~7.0.3",
"eslint": "~9.1.1",
"eslint": "~9.18.0",
"mock-tmp": "~0.0.4",
"nyc": "~15.1.0",
"proxyquire": "~2.1.3",
"tap-arc": "~1.2.2",
"tape": "~5.7.5"
"tap-arc": "~1.3.2",
"tape": "~5.9.0"
}
}
9 changes: 7 additions & 2 deletions src/direct/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ module.exports = function updateLambda (params, callback) {
} = params

// Check the Lambda lifecycle state after each mutation to prevent async update issues
// 40x checks every 250ms = 10s
function checkin (count, callback) {
if (count === 10) {
if (count === 40) {
callback(Error('Timed out waiting to perform Lambda update'))
}
else {
aws.lambda.GetFunctionConfiguration({ FunctionName })
.then(config => {
if (config?.LastUpdateStatus !== 'Successful') {
if (config?.LastUpdateStatus === 'InProgress') {
setTimeout(() => checkin(++count, callback), 250)
}
else if (config?.LastUpdateStatus === 'Failed') {
callback(Error('Lambda update error'))
}
// Only three states: InProgress, Failed, or Successful
else callback()
})
.catch(callback)
Expand Down
10 changes: 6 additions & 4 deletions src/sam/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ module.exports = function samDeploy (params, callback) {
if (name) {
stackname += toLogicalID(name)
}
// For plugins
let stackName = stackname

if (eject) {
update = updater('Deploy [eject]')
Expand Down Expand Up @@ -105,12 +107,12 @@ module.exports = function samDeploy (params, callback) {

// deploy.start plugins
function runStartPlugins (cloudformation, callback) {
plugins.start({ cloudformation, dryRun, inventory, stage }, callback)
plugins.start({ cloudformation, dryRun, inventory, stackName, stage }, callback)
},

// deploy.services plugins
function runServicesPlugins (cloudformation, callback) {
plugins.services({ cloudformation, dryRun, inventory, stage }, callback)
plugins.services({ cloudformation, dryRun, inventory, stackName, stage }, callback)
},

// Fingerprint static assets + ensure ASAP has static.json
Expand Down Expand Up @@ -221,7 +223,7 @@ module.exports = function samDeploy (params, callback) {
// deploy.target plugins
function runTargetPlugins (callback) {
let cloudformation = finalCloudFormation
plugins.target({ cloudformation, dryRun, inventory, stage }, callback)
plugins.target({ cloudformation, dryRun, inventory, stackName, stage }, callback)
},

// Post-deploy static assets
Expand Down Expand Up @@ -252,7 +254,7 @@ module.exports = function samDeploy (params, callback) {
// deploy.end plugins
function runEndPlugins (callback) {
let cloudformation = finalCloudFormation
plugins.end({ cloudformation, dryRun, inventory, stage }, callback)
plugins.end({ cloudformation, dryRun, inventory, stackName, stage }, callback)
},
], callback)
}
4 changes: 2 additions & 2 deletions src/sam/plugins/end.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ let { deepFrozenCopy } = require('@architect/utils')
* deploy.end plugins
*/
module.exports = function endPlugins (params, callback) {
let { cloudformation, dryRun, stage } = params
let { cloudformation, dryRun, stackName, stage } = params
let deployEndPlugins = params.inventory.inv.plugins?._methods?.deploy?.end
if (deployEndPlugins) {
let inventory = deepFrozenCopy(params.inventory)
let { arc } = inventory.inv._project
async function runPlugins () {
for (let plugin of deployEndPlugins) {
await plugin({ arc, cloudformation, dryRun, inventory, stage })
await plugin({ arc, cloudformation, dryRun, inventory, stackName, stage })
}
}
runPlugins()
Expand Down
4 changes: 2 additions & 2 deletions src/sam/plugins/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ let { deepFrozenCopy, getLambdaName, toLogicalID } = require('@architect/utils')
* deploy.services plugins
*/
module.exports = function servicesPlugins (params, callback) {
let { cloudformation, dryRun, stage } = params
let { cloudformation, dryRun, stackName, stage } = params
let serviceDiscoveryPlugins = params.inventory.inv.plugins?._methods?.deploy?.services
if (serviceDiscoveryPlugins) {
let inventory = deepFrozenCopy(params.inventory)
let { arc } = inventory.inv._project
async function runPlugins () {
for (let plugin of serviceDiscoveryPlugins) {
let pluginName = getLambdaName(plugin._plugin)
let result = await plugin({ arc, cloudformation, dryRun, inventory, stage })
let result = await plugin({ arc, cloudformation, dryRun, inventory, stackName, stage })
if (result && Object.keys(result).length) {
Object.entries(result).forEach(([ key, Value ]) => {
let ServiceParam = `${toLogicalID(pluginName)}${toLogicalID(key)}Param`
Expand Down
4 changes: 2 additions & 2 deletions src/sam/plugins/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let { deepFrozenCopy } = require('@architect/utils')
* deploy.start plugins
*/
module.exports = function startPlugins (params, callback) {
let { cloudformation, dryRun, stage } = params
let { cloudformation, dryRun, stackName, stage } = params
let deployStartPlugins = params.inventory.inv.plugins?._methods?.deploy?.start
if (deployStartPlugins) {
let inventory = deepFrozenCopy(params.inventory)
Expand All @@ -15,7 +15,7 @@ module.exports = function startPlugins (params, callback) {
let result
// Plugins accept an option object
if (_type === 'plugin') {
result = await plugin({ arc, cloudformation, dryRun, inventory, stage })
result = await plugin({ arc, cloudformation, dryRun, inventory, stackName, stage })
}
// Legacy macros use ordered args
if (_type === 'macro') {
Expand Down
4 changes: 2 additions & 2 deletions src/sam/plugins/target.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ let { deepFrozenCopy } = require('@architect/utils')
* deploy.target plugins
*/
module.exports = function targetPlugins (params, callback) {
let { cloudformation, dryRun, stage } = params
let { cloudformation, dryRun, stackName, stage } = params
let deployTargetPlugins = params.inventory.inv.plugins?._methods?.deploy?.target
if (deployTargetPlugins) {
let inventory = deepFrozenCopy(params.inventory)
let { arc } = inventory.inv._project
async function runPlugins () {
for (let plugin of deployTargetPlugins) {
await plugin({ arc, cloudformation, dryRun, inventory, stage })
await plugin({ arc, cloudformation, dryRun, inventory, stackName, stage })
}
}
runPlugins()
Expand Down
Loading