Skip to content

What is wrong with my SAM Template?

0

Can somebody guide me on this?. When running sam validate --lint I got the many errors

SAM Template:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Two Lambda functions and two buckets to move and read a CSV file

Globals:
  Function:
    Runtime: python3.11
    CodeUri: src/
    Timeout: 60

Parameters:
  OriginStorageParameter:
    Type: String
    Default: 
      Fn::Sub: "${AWS::StackName}-origin"
  DestinationStorageParameter:
    Type: String
    Default: 
      Fn::Sub: "${AWS::StackName}-destination"

Resources:
  OriginStorage:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: 
        Ref: OriginStorageParameter

  DestinationStorage:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: 
        Ref: DestinationStorageParameter

  ListenerFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: listener.lambda_handler
      FunctionName: s3-listener
      Events:
        S3Event:
          Type: S3
          Properties:
            Bucket: 
              Ref: OriginStorage
            Events: 
              - s3:ObjectCreated:*
            Filter:
              S3Key:
                Rules:
                - Name: suffix
                  Value: ".csv"
      Policies: 
        - S3ReadPolicy:
            BucketName: 
              Ref: OriginStorageParameter

  CopierFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: copier.lambda_handler
      FunctionName: s3-copier
      Events:
        S3Event:
          Type: S3
          Properties:
            Bucket: 
              Ref: DestinationStorage
            Events: 
              - s3:ObjectCreated:*
            Filter:
              S3Key:
                Rules:
                - Name: suffix
                  Value: ".csv"
      Policies: 
        - S3ReadPolicy:
            BucketName: 
              Ref: OriginStorageParameter
        - S3WritePolicy:
            BucketName: 
              Ref: DestinationStorage

and the output of the command...

Enter image description here

Regards

Jona

asked 2 years ago354 views
1 Answer
4
Accepted Answer

Hi, you can't use intrinsic functions like Fn::Sub in the Parameters section. As per https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html. "You can use intrinsic functions only in specific parts of a template. Currently, you can use intrinsic functions in resource properties, outputs, metadata attributes, and update policy attributes. You can also use intrinsic functions to conditionally create stack resources.".

EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago
EXPERT
reviewed 2 years ago
  • Thanks for this valuable information and documentation

    Regards

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.