website
website copied to clipboard
Improve Return Errors to be Accurate
When switching to a new AWS environment, we kept getting this error:
Error: Forbidden: Invalid credentials or this AWS S3 bucket name may already be taken
Credentials were correct. Bucket wasn't taken. If there is a way to return AWS error codes to the user that would be more than a little useful. Currently, one must recreate an S3 bucket and associate it to a CF CDN via the console to find the actual error: ACM:listCertificates
Extra Credit: Improve documentation to list precise policies needed to run.
Lucked into a workaround looking for ways to get debug statements in website component. In short, its a file permission issue with .serverless. Delete the folder and it recreates/works. Still need to fix the response as its misleading.
Found on this forum: https://acloud.guru/forums/serverless-chatbot/discussion/-KpujwFQbfYGwWu_KO0o/sls%20deploy%20--verbose
Full error:
error:
Error: Forbidden: Invalid credentials or this AWS S3 bucket name may already be taken
at ensureBucket (/Users/stevenkling/.serverless/components/registry/npm/@serverless/[email protected]/node_modules/@serverless/aws-s3/utils.js:53:13)
at processTicksAndRejections (internal/process/task_queues.js:85:5)
Source snippet:
const ensureBucket = async (s3, name, debug) => {
try {
debug(`Checking if bucket ${name} exists.`)
await s3.headBucket({ Bucket: name }).promise()
} catch (e) {
if (e.code === 'NotFound') {
debug(`Bucket ${name} does not exist. Creating...`)
await s3.createBucket({ Bucket: name }).promise()
// there's a race condition when using acceleration
// so we need to sleep for a couple seconds. See this issue:
// https://github.com/serverless/components/issues/428
debug(`Bucket ${name} created. Confirming it's ready...`)
await bucketCreation(s3, name)
debug(`Bucket ${name} creation confirmed.`)
} else if (e.code === 'Forbidden' && e.message === null) {
throw Error(`Forbidden: Invalid credentials or this AWS S3 bucket name may already be taken`)
} else if (e.code === 'Forbidden') {
throw Error(`Bucket name "${name}" is already taken.`)
} else {
throw e
}
}
}
Can't upload yml so here:
name: app.dev-bobswift.appfire.app
stage: dev
website:
component: '@serverless/website'
inputs:
code:
src: client/dist
hook: domain=app.dev-bobswift.appfire.app npm run clean:build
region: us-east-1
bucketName: app.dev-bobswift.appfire.app
env: # Environment variables to include in a 'env.js' file with your uploaded code.
API_URL: https://app.dev-bobswift.appfire.app
STAGE: dev
# You can specify a custom domain name for your website.
# You must have a public hosted zone available for this domain in AWS Route53.
# This is done automatically for you if you've purchased the domain via AWS Route53.
domain: app.dev-bobswift.appfire.app
@kling-appfire this is honestly an AWS issue. As you can see from the code, the returned error message is null. So it's less helpful than out message. So we added this message as a guess of what the issue is (it's usually about bucket not existing) instead of keeping the user in the dark.
Regarding your yaml, why can't you upload it? Are you seeing the same error?
GitHub issue won't support upload of .yml. Added .yml.txt here: serverless.yml.txt
It may ultimately have been AWS. I was however able to 'fix' it by deleting the .serverless dir. We're switching between .env files (profiles) and thus between AWS instances (personal vs corporate DTS vs corporate Prod) and something is getting hung up there.
Def was not S3 rights or bucket name taken. If AWS is being 'unfriendly' with their error msgs (and null is pretty dang unfriendly) perhaps a warning for folks switching .env(s)?
deleting ~/.serverless does not help the issue here.