Hello, no solution but one try!
I’ve the exact same problem with buckets.
I want them to stay what ever happen to the serverless project/function.
So I used
DeletionPolicy: Retain
.
Fine for the first run and until you keep the associate CloudFormation stack living.
But when I drop the stack in order to rebuild with a somehow different design but reusing data (thus the bucket)
I can not find any way to do that with serverless.
Try :
- add a Condition not to create the bucket (will fail because it exists)
- but now I need this bucket arn to grant permission to the new lambda
Could not find any way to get arn dynamically with serverless
… maybe I can provide input variables an existing arn (for the existing bucket) or the computed expected bucket arn (it is possible with bucket but not for mush resources)
… but for other resources the arn might not be computed in advance
Looks like a simple requirement : I do not want to loose my data.
But can’t figure how to do it with serverless
Code portion to illustrate :
Custom option to disable bucket creation using Conditions
---
service:
...
custom:
createBucket: ${opt:createBucket, 'true'}
...
resources:
Conditions:
CreateBucket:
Fn::Equals:
- ${self:custom.createBucket}
- true
Resources:
S3BucketMyProjectIngest:
Type: 'AWS::S3::Bucket'
DeletionPolicy: 'Retain'
Condition: 'CreateBucket'
Properties:
BucketName: ${self:custom.IngestBucketName}
...
So not creating those buckets can be achieved with
AWS_PROFILE=serverless serverless deploy --createBucket no
But it fails because of the reference in another resource
S3BucketLambdaPermission:
Type: "AWS::Lambda::Permission"
Properties:
FunctionName:
"Fn::GetAtt":
- 'ProcessFromS3LambdaFunction'
- 'Arn'
...
SourceArn:
"Fn::GetAtt":
- 'S3BucketMyProjectIngest'
- 'Arn'
Error is obviously about the missing resource (disable by the condition)
Template format error: Unresolved resource dependencies [S3BucketMyProjectIngest] in the Resources block of the template
Is there a way to achieve this (“I do not want to loose my data”)?