Reputation: 11881
I have this template:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
example
Parameters:
EnvironmentPrefix:
Type: String
Default: "test-"
Resources:
S3JsonLoggerFunction:
Type: AWS::Serverless::Function
Properties:
Handler: src/handlers/s3-json-logger.s3JsonLoggerHandler
Runtime: nodejs18.x
Architectures:
- x86_64
MemorySize: 128
Timeout: 60
Policies:
- S3ReadPolicy:
BucketName:
!Fn::ImportValue:
!Sub "${EnvironmentPrefix}example-bucket"
Events:
S3NewObjectEvent:
Type: S3
Properties:
Bucket:
!Fn::ImportValue:
!Sub "${EnvironmentPrefix}example-bucket"
Events: s3:ObjectCreated:*
Filter:
S3Key:
Rules:
- Name: prefix
Value: "changelog/"
Why does it fail with this error???
Error: Failed to parse template: while parsing a block mapping
in "<unicode string>", line 23, column 13:
BucketName:
^
expected <block end>, but found '<tag>'
in "<unicode string>", line 25, column 17:
!Sub "${EnvironmentPrefix}example-b ...
^
I've been staring at this and comparing it to the examples at https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-templates.html and can't figure out what's different!!!
Upvotes: 0
Views: 824
Reputation: 14906
I think your syntax of !Fn::ImportValue:
is wrong.
It should be just Fn::ImportValue:
without the !
, as !
is a short-form alias for Fn::
.
Policies:
- S3ReadPolicy:
BucketName:
Fn::ImportValue:
!Sub "${EnvironmentPrefix}example-bucket"
Docs are here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-importvalue.html
Upvotes: 3