Skip to content

func-api-devices-backup-delete

Overview

Deploys the Lambda function that handles DELETE /devices/{uuid}/backup. Called by the Controller firmware to remove a stored configuration backup from S3 and clear last_backup_date from the device's DynamoDB record. Authenticates the request by verifying an ECDSA P-256 signature over SHA-256(nonce || timestamp). This route has no Cognito JWT authorizer — it is authenticated solely by the device's cryptographic signature.

CloudFormation Stack

firefly-func-api-devices-backup-delete

CloudWatch Logs

SettingValue
Log group/aws/lambda/firefly-func-api-devices-backup-delete
Retention30 days

Dependencies

Deploy Dependencies

WorkflowReason
api-gatewayApiId resolved from stack outputs
dynamodb-devicesTable must exist before the function is deployed and granted read/write access
shared-layerLambda layer must exist before function deployment
s3-device-backupsS3 bucket must exist before the function is deployed and granted delete access

Delete Dependencies

None — this workflow has no prerequisites.

Required By

Required By Deploy

WorkflowReason
run-integration-testsEndpoint must be live before integration tests run

Required By Delete

WorkflowReason
delete-api-gatewayRoute registration must be removed before the API Gateway stack is deleted
delete-dynamodb-devicesIAM permissions referencing the table must be removed first
delete-shared-layerLayer reference must be removed before the layer stack is deleted
delete-s3-device-backupsIAM permissions referencing the bucket must be removed first

IAM Permissions

The Lambda execution role (firefly-func-api-devices-backup-delete-role) is granted:

  • dynamodb:GetItem, dynamodb:UpdateItem on firefly-devices
  • s3:DeleteObject on the device backups bucket
  • appconfig:StartConfigurationSession, appconfig:GetLatestConfiguration on *

Deploy Workflow

Description

Resolves the HTTP API Gateway ID, shared layer ARN, and AppConfig extension layer ARN from CloudFormation stack outputs. Installs cryptography, cffi, and pycparser as arm64 binary dependencies alongside the Lambda source, then performs a SAM deploy.

Steps

  1. Configure AWS credentials.
  2. Look up ApiId from the firefly-api-gateway stack output.
  3. Look up SharedLayerArn from the firefly-shared-layer stack output.
  4. Look up AppConfigExtensionLayerArn from the firefly-shared-layer stack output.
  5. Install Python arm64 dependencies into lambdas/func-api-devices-backup-delete/.
  6. SAM deploy firefly-func-api-devices-backup-delete with parameters:
    • ApiId
    • SharedLayerArn
    • AppConfigExtensionLayerArn
    • BackupBucketName

Delete Workflow

Description

Calls sam delete to remove the Lambda function, its IAM role, and the API Gateway route integration. Also deletes the CloudWatch log group.

Steps

  1. Configure AWS credentials.
  2. SAM delete firefly-func-api-devices-backup-delete.
  3. Delete CloudWatch log group /aws/lambda/firefly-func-api-devices-backup-delete.

Failure Scenarios

ScenarioBehavior
firefly-api-gateway stack not founddescribe-stacks returns an error; workflow fails before SAM deploy. Deploy api-gateway first.
firefly-dynamodb-devices stack not deployedFunction deploys but returns errors at runtime. Deploy dynamodb-devices first.
firefly-shared-layer stack not foundLayer ARN lookup fails; SAM deploy is not attempted. Deploy shared-layer first.
firefly-s3-device-backups stack not deployedFunction deploys but S3 operations fail at runtime. Deploy s3-device-backups first.
Device UUID not foundLambda returns 401 Unauthorized.
Timestamp outside the acceptance windowLambda returns 401 Unauthorized.
Invalid or mismatched signatureLambda returns 401 Unauthorized.