以下は、このセットアップのSAMテンプレートを作成するためのAWS SAM CLIコマンドの例です：

```
sam init --runtime python3.8
cd sam-app/
sam build
sam package --output-template-file packaged.yaml
sam deploy --template-file packaged.yaml --stack-name s3-resize-stack --capabilities CAPABILITY_IAM
```

これがSamテンプレートだ：

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  S3Bucket:
    Type: AWS::S3::Bucket
    DeletionPolicy: Retain
    Properties:
      BucketName: my-resize-bucket
      NotificationConfiguration:
        LambdaConfigurations:
          - Event: s3:ObjectCreated:*
            Function: !GetAtt LambdaResizeFunction.Arn

  LambdaResizeFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: resize_function.py
      Handler: index.handler
      Runtime: python3.8
      Environment:
        Variables:
          S3_BUCKET: !Ref S3Bucket
      Policies:
        - S3CrudPolicy:
            BucketName: !Ref S3Bucket
````

そして、アップロードされたファイルのサイズを変更するLambda関数のPythonスクリプトの例です：

```
import boto3

def handler(event, context):
    s3 = boto3.client('s3')
    bucket_name = os.environ['S3_BUCKET']

    for record in event['Records']:
        file_key = record['s3']['object']['key']
        # resize the file using the boto3 library
        # save the resized file back to S3 with the same key
        s3.upload_file(resized_file, bucket_name, file_key)
```

この設定により、Lambda関数は新しいオブジェクトがアップロードされるたびに1回だけトリガーされ、同じキーを使ってファイルのサイズを変更することができます。
Here's an example AWS SAM CLI command to create a SAM template for this setup:
sam init --runtime python3.8
cd sam-app/
sam build
sam package --output-template-file packaged.yaml
sam deploy --template-file packaged.yaml --stack-name s3-resize-stack --capabilities CAPABILITY_IAM

Here's the Sam template: 

---
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  S3Bucket:
    Type: AWS::S3::Bucket
    DeletionPolicy: Retain
    Properties:
      BucketName: my-resize-bucket
      NotificationConfiguration:
        LambdaConfigurations:
          - Event: s3:ObjectCreated:*
            Function: !GetAtt LambdaResizeFunction.Arn

  LambdaResizeFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: resize_function.py
      Handler: index.handler
      Runtime: python3.8
      Environment:
        Variables:
          S3_BUCKET: !Ref S3Bucket
      Policies:
        - S3CrudPolicy:
            BucketName: !Ref S3Bucket

And here's an example Python script for the Lambda function that resizes the uploaded file:

import boto3

def handler(event, context):
    s3 = boto3.client('s3')
    bucket_name = os.environ['S3_BUCKET']

    for record in event['Records']:
        file_key = record['s3']['object']['key']
        # resize the file using the boto3 library
        # save the resized file back to S3 with the same key
        s3.upload_file(resized_file, bucket_name, file_key)

This setup ensures that the Lambda function is triggered only once per new object uploaded and resizes the file using the same key.