- Newest
- Most votes
- Most comments
Hi,
your BucketName: somebucket-${EnvironmentName} is incomplete. You must change it to BucketName: !Sub somebucket-${EnvironmentName} to allow substitution of ${EnvironmentName} to happen.
See !Sub at https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html
Best,
Didier
The error message you're encountering suggests that there's an issue with the CloudFormation template, specifically related to string processing. The problem likely stems from how you're trying to construct the bucket name.
In your template, you're using a parameter substitution syntax that isn't correct for CloudFormation. CloudFormation doesn't support the ${EnvironmentName} syntax directly in the BucketName property. Instead, you should use the Fn::Sub intrinsic function (or its shorthand !Sub) to perform string substitution.
Here's how you can modify your template to correctly use the EnvironmentName parameter in the BucketName:
AWSTemplateFormatVersion: 2010-09-09 Parameters: EnvironmentName: Type: String Default: dev Description: Refer the current environment AllowedValues: ['dev', 'prod', 'preprod'] ConstraintDescription: Select 'dev' or 'prod' or 'preprod' Resources: DigidocsGeneralBucket: Type: 'AWS::S3::Bucket' Properties: BucketName: !Sub 'somebucket-${EnvironmentName}' Tags: - Key: Application Value: someapplication
By using the !Sub function, you're telling CloudFormation to substitute the ${EnvironmentName} with the actual value of the EnvironmentName parameter.
This should resolve the "Cannot invoke "String.hashCode()" because "<local4>" is null" error you're experiencing. The error was likely caused by CloudFormation trying to process an invalid string substitution, resulting in a null value being passed to an internal method.
Remember that S3 bucket names must be globally unique across all AWS accounts, so you might want to add some additional uniqueness to your bucket name to avoid conflicts, especially if you're creating multiple environments.
Sources
Resource handler returned message: "<resourceName> already exists | AWS re:Post
Access Denied (Service: S3, Status Code: 403) | AWS re:Post
Relevant content
- AWS OFFICIALUpdated 5 years ago
