- Newest
- Most votes
- Most comments
Hi
If you are passing parameters to the stack that you want to use in the bucket name then this is possible.
There are two ways I use to create bucket names. Note, all this can also be used in a Lambda if you are putting the lambda code "inline" in the CloudFormation template.
First with a parameter for bucket name [bucketname].
In the resource section I can then just use "!Ref bucketname" under the bucket resource to reference the parameter.
The other way I have used, especially in multi-landscape, is referencing one or many parameters and concatenating text along with text using !Sub.
For example with parameters for [landscape], [tier], [environment] and pseudo parameters I could create the following naming.
!Sub bucket-${AWS::Region}-${landscape}-${tier}-${environment}.
Might be worth taking a look at the AWS CloudFormation Workshop.
Hope this helps and solve your challenges.
Thank you, Mr. Ford, for your response. I do not want to use the parameter as I want the name to be dynamically created. I will try the second option you have suggested.
So, I used !Sub to define the bucket name under Custom Resource section, but the name never gets passed to the function.
Relevant content
- Accepted Answerasked 3 years ago
- asked 4 years ago
- AWS OFFICIALUpdated 2 months ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
Can you add the code here? Why are you using a custom resource?
MyS3Resource: Type: AWS::CloudFormation::CustomResource Properties: ServiceToken: !GetAtt S3BucketLambda.Arn BucketName: !Sub cache-${AWS::AccountId} Region: !Ref AWS::Region
S3BucketLambda: Type: AWS::Lambda::Function Properties: FunctionName: Index Handler: index.handler Runtime: python3.7 Role: !Join ["", ["arn:aws:iam::", !Ref "AWS::AccountId", ":role/companyname/aws-projectname-lambda-role"]] MemorySize: 128 Timeout: 10 Description: "Testing S3" Environment: Variables: BucketName: "cache-11223344" Code: ZipFile: | import boto3 import os import cfnresponse