Custom bucket configuration not doing anything
Straight from the docs, I have
provider:
s3:
myBucket:
name: ${self:custom.bucketName}
versioningConfiguration:
Status: Enabled
But versioningConfiguration and other camel-cases, cloudformation properties have no effect. I'm not getting an error or any warnings; it just simply has no effect
service: example-repo
package:
exclude:
- "venv/**"
provider:
s3:
exampleBucket:
name: testbucket3894vcnv
# versioningConfiguration:
# Status: Enabled
accessControl: Private
publicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
bucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
name: aws
runtime: python3.8
memorySize: 512
timeout: 300
region: us-west-2
stage: development
functions:
triggerResultsSm:
handler: main.handler
events:
- s3:
bucket: testbucket3894vcnv
event: s3:ObjectCreated:*
Serverless: Load command interactiveCli
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command config:tabcompletion
Serverless: Load command config:tabcompletion:install
Serverless: Load command config:tabcompletion:uninstall
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command upgrade
Serverless: Load command uninstall
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command generate-event
Serverless: Load command test
Serverless: Load command dashboard
Serverless: Load command output
Serverless: Load command output:get
Serverless: Load command output:list
Serverless: Load command param
Serverless: Load command param:get
Serverless: Load command param:list
Serverless: Load command studio
Serverless: Skipping variables resolution with old resolver (new resolver reported no more variables to resolve)
Serverless: Deprecation warning: Support for "package.include" and "package.exclude" will be removed with next major release. Please use "package.patterns" instead
More Info: https://www.serverless.com/framework/docs/deprecations/#NEW_PACKAGE_PATTERNS
Serverless: Deprecation warning: Resolution of lambda version hashes was improved with better algorithm, which will be used in next major release.
Switch to it now by setting "provider.lambdaHashingVersion" to "20201221"
More Info: https://www.serverless.com/framework/docs/deprecations/#LAMBDA_HASHING_VERSION_V2
Serverless: Invoke deploy
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Invoke aws:package:finalize
Serverless: Invoke aws:common:moveArtifactsToPackage
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:deploy:deploy
Serverless: Service files not changed. Skipping deployment...
Serverless: Invoke aws:info
Service Information
service: example-repo
stage: development
region: us-west-2
stack: example-repo-development
resources: 8
api keys:
None
endpoints:
None
functions:
triggerResultsSm: example-repo-development-triggerResultsSm
layers:
None
Serverless: Invoke aws:deploy:finaliz
Installed version
Framework Core: 2.48.0 (local)
Plugin: 5.4.1
SDK: 4.2.3
Components: 3.12.0
Hello @brno32 :wave: Thanks for reporting. In your event you're referencing name of the bucket testbucket3894vcnv while in provider.s3 you've configured properties for bucket exampleBucket. Please ensure that these match if you want to apply the extra configuration from provider.s3 - please reference the docs, in the example in both places it has bucketOne. Please let me know if that solved your issue.
@pgrzesik Ahh, I had no idea this was the problem. I created a similar post on the forum https://forum.serverless.com/t/s3-bucket-properties-not-applied/15455
After researching, variables cannot be used as keys in yml https://www.serverless.com/framework/docs/providers/aws/guide/variables#syntax
The alternative is to generate them with js https://www.serverless.com/framework/docs/providers/aws/guide/variables/#exporting-a-function
A final configuration may look like:
# serverless.yml
provider:
s3: ${file(./serverless-config/s3.js):s3}
// ./serverless-config/s3.js
module.exports = async ({ resolveVariable }) => {
return {
s3: {
[await resolveVariable('self:custom.buckets.s3UploadInstant')]: {
name: await resolveVariable('self:custom.buckets.s3UploadInstant'),
versioningConfiguration: {
Status: 'Enabled',
},
},
[await resolveVariable('self:custom.buckets.s3UploadBatch')]: {
name: await resolveVariable('self:custom.buckets.s3UploadBatch'),
versioningConfiguration: {
Status: 'Enabled',
},
},
},
};
};
To check your configuration, use sls package, as the --noDeploy flag has been deprecated.
Thanks for sharing @jlarmstrongiv :bow: That's correct, it's not possible to use variables as keys and the only "workaround" is to switch to js/ts-based config if you want to achieve it.
@pgrzesik glad to! I didn’t realize it was possible to make a typescript version (found the docs)—do you know what the proper types are for the example above?
@jlarmstrongiv I'm no TS expert, but this template is a really good starting point for working with TS-based config: https://github.com/serverless/serverless/tree/master/lib/plugins/create/templates/aws-nodejs-typescript
Wait, so what's the expected way to use this without using JS? bucket names have to be static? or does the function event check for a bucket in the provider section whose key is "bucket"?
Edit: Nope, it doesn't do that.
So bucket names have to be entirely static for it to be possible to configure them? How am I supposed to manage multiple environments?