0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

「LocalStack実践入門」を読んでみた(Ch.03)

Posted at

今回はこのワークショップをやっていきます。

そのまま進めていっても淡々と進めても自分の場合は身につかない可能性が高いの以下の2つを変更してワークショップを進めていこうと思います。

  • 環境として、上記に書かれているGitHub Codespacesではなく、前回自分で作った環境(Colima+Localstack)を使って実施していきます
  • LocalStack Resource Browserを使わない

詳細な解説などは、上記のLocalStack実践入門をお読みください。

colimaを起動

$ colima start
INFO[0000] starting colima                              
INFO[0000] runtime: docker                              
INFO[0002] starting ...                                  context=vm
INFO[0013] provisioning ...                              context=docker
INFO[0014] starting ...                                  context=docker
INFO[0015] done 

Localstackの確認

$ localstack --version
LocalStack CLI 4.7.0
$ localstack status
┌─────────────────┬───────────────────────────────────────────────────────┐
│ Runtime version │ 4.7.1.dev129                                          │
│ Docker image    │ tag: latest, id: 9eaa75b0a908, 📆 2025-09-05T14:29:21 │
│ Runtime status  │ ✖ stopped                                             │
└─────────────────┴───────────────────────────────────────────────────────┘

locakstackは停止されていますので、起動してます。

Localstackの起動

$ localstack start -d

     __                     _______ __             __
    / /   ____  _________ _/ / ___// /_____ ______/ /__
   / /   / __ \/ ___/ __ `/ /\__ \/ __/ __ `/ ___/ //_/
  / /___/ /_/ / /__/ /_/ / /___/ / /_/ /_/ / /__/ ,<
 /_____/\____/\___/\__,_/_//____/\__/\__,_/\___/_/|_|

- LocalStack CLI: 4.7.0
- Profile: default
- App: https://app.localstack.cloud

[14:45:45] starting LocalStack in Docker mode 🐳                                                        localstack.py:532
           preparing environment                                                                        bootstrap.py:1309
           configuring container                                                                        bootstrap.py:1317
           starting container                                                                           bootstrap.py:1327
[14:45:46] detaching                                                                                    bootstrap.py:1331
$ localstack status
┌─────────────────┬───────────────────────────────────────────────────────┐
│ Runtime version │ 4.7.1.dev129                                          │
│ Docker image    │ tag: latest, id: 9eaa75b0a908, 📆 2025-09-05T14:29:21 │
│ Runtime status  │ ✔ running (name: "localstack-main", IP: 172.17.0.2)   │
└─────────────────┴───────────────────────────────────────────────────────┘

LocalStack用のアクセスキーの設定

$ aws configure
AWS Access Key ID [None]: DUMMY
AWS Secret Access Key [None]: DUMMY
Default region name [None]: ap-northeast-1
Default output format [None]: json

ワークショップのGitHubリポジトリをクローンする

$ git clone https://github.com/kakakakakku/aws-serverless-pattern-workshop-using-localstack.git
Cloning into 'aws-serverless-pattern-workshop-using-localstack'...
remote: Enumerating objects: 80, done.
remote: Counting objects: 100% (80/80), done.
remote: Compressing objects: 100% (47/47), done.
remote: Total 80 (delta 26), reused 74 (delta 22), pack-reused 0 (from 0)
Receiving objects: 100% (80/80), 450.04 KiB | 9.78 MiB/s, done.
Resolving deltas: 100% (26/26), done.
 $ ls
aws-serverless-pattern-workshop-using-localstack
$ cd aws-serverless-pattern-workshop-using-localstack

Chapter 3をやってみる

$ cd chapter03
$ ls 
images		pyproject.toml	samconfig.toml	src		template.yaml

サーバレスアプリケーションをデプロイする

$ samlocal build      
zsh: command not found: samlocal

エラーになってしまいました。
samlocalがインストールできていなかったようです。

$ brew install aws-sam-cli
実行結果
==> Fetching downloads for: aws-sam-cli
==> Downloading https://ghcr.io/v2/homebrew/core/aws-sam-cli/manifests/1.144.0
################################################################################################################### 100.0%
==> Fetching dependencies for aws-sam-cli: ca-certificates, certifi, pycparser, cffi and cryptography
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/manifests/2025-09-09
################################################################################################################### 100.0%
==> Fetching ca-certificates
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/blobs/sha256:a74a274a402f29cff2e1bb595a5253c20d7503a08617
################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/certifi/manifests/2025.8.3
################################################################################################################### 100.0%
==> Fetching certifi
==> Downloading https://ghcr.io/v2/homebrew/core/certifi/blobs/sha256:b9364932b2e97249a92c11076b9cabe13ac5fdad56eac069f3ad
################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/pycparser/manifests/2.23
################################################################################################################### 100.0%
==> Fetching pycparser
==> Downloading https://ghcr.io/v2/homebrew/core/pycparser/blobs/sha256:20df01e401f66b31119275739885166b381c62cddac34c2af5
################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/cffi/manifests/2.0.0
################################################################################################################### 100.0%
==> Fetching cffi
==> Downloading https://ghcr.io/v2/homebrew/core/cffi/blobs/sha256:6775016658efc6fafc45b5599b2ea47e5b12ca2c2f2ee9838d935e0
################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/cryptography/manifests/45.0.7
################################################################################################################### 100.0%
==> Fetching cryptography
==> Downloading https://ghcr.io/v2/homebrew/core/cryptography/blobs/sha256:7b775263cb1cefd9cff15d7cbaea3bb70c98024c4b9ccb2
################################################################################################################### 100.0%
==> Fetching aws-sam-cli
==> Downloading https://ghcr.io/v2/homebrew/core/aws-sam-cli/blobs/sha256:bd24749c91e1f4496554fe06a861d4b02f78972145a81330
################################################################################################################### 100.0%
==> Installing dependencies for aws-sam-cli: ca-certificates, certifi, pycparser, cffi and cryptography
==> Installing aws-sam-cli dependency: ca-certificates
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/manifests/2025-09-09
Already downloaded: /Users/nomura/Library/Caches/Homebrew/downloads/426185977a48495074d7594bb26de3d3f6afafc4a03c0d972deaba1cc2ba2861--ca-certificates-2025-09-09.bottle_manifest.json
==> Pouring ca-certificates--2025-09-09.all.bottle.tar.gz
==> Regenerating CA certificate bundle from keychain, this may take a while...
🍺  /opt/homebrew/Cellar/ca-certificates/2025-09-09: 4 files, 232.9KB
==> Installing aws-sam-cli dependency: certifi
==> Downloading https://ghcr.io/v2/homebrew/core/certifi/manifests/2025.8.3
Already downloaded: /Users/nomura/Library/Caches/Homebrew/downloads/29b9ac15cf934be4a643db102401daebd164075aa1ed1cd889bc2de96f15bf3c--certifi-2025.8.3.bottle_manifest.json
==> Pouring certifi--2025.8.3.all.bottle.tar.gz
🍺  /opt/homebrew/Cellar/certifi/2025.8.3: 27 files, 24.8KB
==> Installing aws-sam-cli dependency: pycparser
==> Downloading https://ghcr.io/v2/homebrew/core/pycparser/manifests/2.23
Already downloaded: /Users/nomura/Library/Caches/Homebrew/downloads/211ff26e2935d9c7c66d8fa9d38ffb6777b2b659ca434056d6b46ae6bdf0b16d--pycparser-2.23.bottle_manifest.json
==> Pouring pycparser--2.23.all.bottle.tar.gz
🍺  /opt/homebrew/Cellar/pycparser/2.23: 74 files, 1.2MB
==> Installing aws-sam-cli dependency: cffi
==> Downloading https://ghcr.io/v2/homebrew/core/cffi/manifests/2.0.0
Already downloaded: /Users/nomura/Library/Caches/Homebrew/downloads/cdc6eed0f6e98e212f9b5d99551bf427baf0eae0a22a7cdd28e979d0d5432fb3--cffi-2.0.0.bottle_manifest.json
==> Pouring cffi--2.0.0.arm64_sequoia.bottle.tar.gz
🍺  /opt/homebrew/Cellar/cffi/2.0.0: 68 files, 1.2MB
==> Installing aws-sam-cli dependency: cryptography
==> Downloading https://ghcr.io/v2/homebrew/core/cryptography/manifests/45.0.7
Already downloaded: /Users/nomura/Library/Caches/Homebrew/downloads/7f1ce1f7a53a9a3d807d9aca64fe0f0f3e0195965c25167b97fd38e7db604511--cryptography-45.0.7.bottle_manifest.json
==> Pouring cryptography--45.0.7.arm64_sequoia.bottle.tar.gz
🍺  /opt/homebrew/Cellar/cryptography/45.0.7: 218 files, 9MB
==> Installing aws-sam-cli
==> Pouring aws-sam-cli--1.144.0.arm64_sequoia.bottle.tar.gz
🍺  /opt/homebrew/Cellar/aws-sam-cli/1.144.0: 15,045 files, 217.4MB
==> Running `brew cleanup aws-sam-cli`...
Disable this behaviour by setting `HOMEBREW_NO_INSTALL_CLEANUP=1`.
Hide these hints with `HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).
==> No outdated dependents to upgrade!
==> Caveats
zsh completions have been installed to:
  /opt/homebrew/share/zsh/site-functions

aws-sam-localをインストールしようとしたらエラーになってしまいました。

$ pip install aws-sam-local
ERROR: Could not find a version that satisfies the requirement aws-sam-local (from versions: none)

ERROR: No matching distribution found for aws-sam-local

Geminiに聞いてみると、今はaws-sam-cliの機能が向上し、samlocalを使わなくても直接LocalStackと連携でできますと言われたのでGeminiを信じて作業していきます。

samconfig.tomlファイルを編集します。

$ vi samconfig.toml
samconfig.toml
version = 0.1
[default.deploy.parameters]
stack_name = "chapter03-stack"
resolve_s3 = true
endpoint_url = "https://localhost:4566"
s3_prefix = "chapter03-stack"
region = "ap-northeast-1"
capabilities = "CAPABILITY_IAM"
image_repositories = []
profile = "localstack"

設定後にsam buildを実行すると以下のようなエラーになりました。

$ sam build
Building codeuri: /Users/nomura/localstack/aws-serverless-pattern-workshop-using-localstack/chapter03/src runtime:        
python3.12 architecture: x86_64 functions: Function                                                                       

Build Failed
Error: PythonPipBuilder:Validation - Binary validation failed for python, searched for python in following locations  : ['/Users/nomura/.pyenv/shims/python', '/Users/nomura/.pyenv/shims/python3', '/opt/homebrew/bin/python3', '/usr/bin/python3'] which did not satisfy constraints for runtime: python3.12. Do you have python for runtime: python3.12 on your PATH?

これは、template.yamlにpython3.12と指定されているからだと思われるのでバージョンを3.13にしてみます。

$ sam build       
Building codeuri: /Users/nomura/localstack/aws-serverless-pattern-workshop-using-localstack/chapter03/src runtime:        
python3.13 architecture: x86_64 functions: Function                                                                       
 Running PythonPipBuilder:ResolveDependencies                                                                             
 Running PythonPipBuilder:CopySource                                                                                      

Build Succeeded

Built Artifacts  : .aws-sam/build
Built Template   : .aws-sam/build/template.yaml

Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke
[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
[*] Deploy: sam deploy --guided

buildは、うまく行ったようなので、次はdeployしてみます。

$ sam deploy
	Creating the required resources...
Error: Failed to create managed resources: An error occurred (InvalidClientTokenId) when calling the CreateChangeSet operation: The security token included in the request is invalid.

うまくいかないのでGeminiに聞いたところsam deploy --debugでデバッグログを取得してくれとのことでしたので、ログを取得しました。

$ sam deploy --debug
デバッグログ
2025-09-15 05:32:45,702 | Config file location: /Users/nomura/localstack/aws-serverless-pattern-workshop-using-localstack/chapter03/samconfig.toml             
2025-09-15 05:32:45,703 | Loading configuration values from [default.['deploy'].parameters] (env.command_name.section) in config file at                       
'/Users/nomura/localstack/aws-serverless-pattern-workshop-using-localstack/chapter03/samconfig.toml'...                                                        
2025-09-15 05:32:45,704 | Configuration values successfully loaded.                                                                                            
2025-09-15 05:32:45,704 | Configuration values are: {'stack_name': 'chapter03-stack', 'resolve_s3': True, 'endpoint_url': 'http://localhost:4566', 's3_prefix':
'chapter03-stack', 'region': 'ap-northeast-1', 'capabilities': 'CAPABILITY_IAM', 'image_repositories': [], 'profile': 'localstack'}                            
2025-09-15 05:32:45,705 | Using SAM Template at                                                                                                                
/Users/nomura/localstack/aws-serverless-pattern-workshop-using-localstack/chapter03/.aws-sam/build/template.yaml                                               
2025-09-15 05:32:45,718 | Using config file: samconfig.toml, config environment: default                                                                       
2025-09-15 05:32:45,718 | Expand command line arguments to:                                                                                                    
2025-09-15 05:32:45,718 | --template_file=/Users/nomura/localstack/aws-serverless-pattern-workshop-using-localstack/chapter03/.aws-sam/build/template.yaml     
--fail_on_empty_changeset --on_failure=ROLLBACK --max_wait_duration=60 --stack_name=chapter03-stack --s3_prefix=chapter03-stack --resolve_s3                   
--capabilities=['CAPABILITY_IAM']                                                                                                                              
2025-09-15 05:32:45,947 | Managed S3 stack [aws-sam-cli-managed-default] not found. Creating a new one.                                                        
	Creating the required resources...
2025-09-15 05:32:45,961 | Failed to create managed resources                                                                                                   
Traceback (most recent call last):                                                                                                                             
  File "/opt/homebrew/Cellar/aws-sam-cli/1.144.0/libexec/lib/python3.13/site-packages/samcli/lib/utils/managed_cloudformation_stack.py", line 167, in          
_create_or_get_stack                                                                                                                                           
    stack = _create_stack(                                                                                                                                     
        cloudformation_client, stack_name, template_body, parameter_overrides                                                                                  
    )  # exceptions are not captured from subcommands                                                                                                          
  File "/opt/homebrew/Cellar/aws-sam-cli/1.144.0/libexec/lib/python3.13/site-packages/samcli/lib/utils/managed_cloudformation_stack.py", line 251, in          
_create_stack                                                                                                                                                  
    change_set_resp = cloudformation_client.create_change_set(                                                                                                 
        StackName=stack_name,                                                                                                                                  
    ...<5 lines>...                                                                                                                                            
        Parameters=parameters,                                                                                                                                 
    )                                                                                                                                                          
  File "/opt/homebrew/Cellar/aws-sam-cli/1.144.0/libexec/lib/python3.13/site-packages/botocore/client.py", line 602, in _api_call                              
    return self._make_api_call(operation_name, kwargs)                                                                                                         
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                         
  File "/opt/homebrew/Cellar/aws-sam-cli/1.144.0/libexec/lib/python3.13/site-packages/botocore/context.py", line 123, in wrapper                               
    return func(*args, **kwargs)                                                                                                                               
  File "/opt/homebrew/Cellar/aws-sam-cli/1.144.0/libexec/lib/python3.13/site-packages/botocore/client.py", line 1078, in _make_api_call                        
    raise error_class(parsed_response, operation_name)                                                                                                         
botocore.exceptions.ClientError: An error occurred (InvalidClientTokenId) when calling the CreateChangeSet operation: The security token included in the       
request is invalid.                                                                                                                                            
2025-09-15 05:32:45,969 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics                           
2025-09-15 05:32:46,024 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics                           
2025-09-15 05:32:46,024 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '23c09ba3-302c-4c19-a131-35f93a09b7ab', 'installationId':               
'6231ce56-f8c3-4d62-9c54-1da1c88b62a3', 'sessionId': '2f8d30a0-5a7a-42a0-9bbf-975ce1512344', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.13.7',
'samcliVersion': '1.144.0', 'awsProfileProvided': True, 'debugFlagProvided': True, 'region': 'ap-northeast-1', 'commandName': 'sam deploy',                    
'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName': '644de0f55ae1ee73ef08416767d4d71b0d374c1029fa316c55bab791b790551c',       
'initialCommit': None, 'containerEngine': 'docker-default'}, 'duration': 251, 'exitReason': 'ManagedStackError', 'exitCode': 1}}]}                             
2025-09-15 05:32:46,025 | Unable to find Click Context for getting session_id.                                                                                 
2025-09-15 05:32:46,026 | Sending Telemetry: {'metrics': [{'events': {'requestId': '53a3a800-45b2-4489-91d8-3a0165e8ac71', 'installationId':                   
'6231ce56-f8c3-4d62-9c54-1da1c88b62a3', 'sessionId': '2f8d30a0-5a7a-42a0-9bbf-975ce1512344', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.13.7',
'samcliVersion': '1.144.0', 'commandName': 'sam deploy', 'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value':       
'.toml', 'thread_id': '3e8c5bc562af400b8e6a4c50f34413d9', 'time_stamp': '2025-09-14 20:32:45.702', 'exception_name': None}, {'event_name':                     
'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': 'e9491e21ef8c49469101e035e06dfe86', 'time_stamp': '2025-09-14 20:32:45.717', 'exception_name':  
None}], 'containerEngine': 'docker-default'}}}]}                                                                                                               
2025-09-15 05:32:46,542 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)     
2025-09-15 05:32:46,543 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)     
Error: Failed to create managed resources: An error occurred (InvalidClientTokenId) when calling the CreateChangeSet operation: The security token included in the request is invalid.

Geminiでログを解析すると

2025-09-15 05:32:45,947 | Managed S3 stack [aws-sam-cli-managed-default] not found. Creating a new one.

これは、SAM CLIがあなたのスタック(chapter03-stack)をデプロイする前に、SAM CLI自身が使用する管理用のS3バケットを準備しようとしていることを示しています。この管理用バケットはaws-sam-cli-managed-defaultという名前のCloudFormationスタックによって作成されます。

問題は、この「管理用スタックの作成」という内部的な処理が、samconfig.tomlに記述されたendpoint_urlの設定を無視して、実際のAWSのエンドポイントにアクセスしにいってしまう点にあります。

と言われて環境変数を設定しろと言われたので、環境変数を設定しました。

$ export AWS_ENDPOINT_URL=http://localhost:4566

再度デプロイを実行してみます。

$ sam deploy --debug 
デバッグログ
2025-09-15 09:46:10,233 | Config file location: /Users/nomura/localstack/aws-serverless-pattern-workshop-using-localstack/chapter03/samconfig.toml             
2025-09-15 09:46:10,234 | Loading configuration values from [default.['deploy'].parameters] (env.command_name.section) in config file at                       
'/Users/nomura/localstack/aws-serverless-pattern-workshop-using-localstack/chapter03/samconfig.toml'...                                                        
2025-09-15 09:46:10,235 | Configuration values successfully loaded.                                                                                            
2025-09-15 09:46:10,235 | Configuration values are: {'stack_name': 'chapter03-stack', 'resolve_s3': True, 'endpoint_url': 'http://localhost:4566', 's3_prefix':
'chapter03-stack', 'region': 'ap-northeast-1', 'capabilities': 'CAPABILITY_IAM', 'image_repositories': [], 'profile': 'localstack'}                            
2025-09-15 09:46:10,236 | Using SAM Template at                                                                                                                
/Users/nomura/localstack/aws-serverless-pattern-workshop-using-localstack/chapter03/.aws-sam/build/template.yaml                                               
2025-09-15 09:46:10,251 | Using config file: samconfig.toml, config environment: default                                                                       
2025-09-15 09:46:10,251 | Expand command line arguments to:                                                                                                    
2025-09-15 09:46:10,251 | --template_file=/Users/nomura/localstack/aws-serverless-pattern-workshop-using-localstack/chapter03/.aws-sam/build/template.yaml     
--fail_on_empty_changeset --on_failure=ROLLBACK --max_wait_duration=60 --stack_name=chapter03-stack --s3_prefix=chapter03-stack --resolve_s3                   
--capabilities=['CAPABILITY_IAM']                                                                                                                              
2025-09-15 09:46:10,458 | Managed S3 stack [aws-sam-cli-managed-default] not found. Creating a new one.                                                        
	Creating the required resources...
	Successfully created!

	Managed S3 bucket: aws-sam-cli-managed-default-samclisourcebucket-5ae83a12
	Auto resolution of buckets can be turned off by setting resolve_s3=False
	To use a specific S3 bucket, set --s3-bucket=<bucket_name>
	Above settings can be stored in samconfig.toml
2025-09-15 09:46:25,548 | No Parameters detected in the template                                                                                               
2025-09-15 09:46:25,565 | There is no customer defined id or cdk path defined for resource UploadBucket, so we will use the resource logical id as the resource
id                                                                                                                                                             
2025-09-15 09:46:25,566 | Sam customer defined id is more priority than other IDs. Customer defined id for resource Function is Function                       
2025-09-15 09:46:25,566 | There is no customer defined id or cdk path defined for resource ProcessingBucket, so we will use the resource logical id as the     
resource id                                                                                                                                                    
2025-09-15 09:46:25,567 | 0 stacks found in the template                                                                                                       
2025-09-15 09:46:25,567 | No Parameters detected in the template                                                                                               
2025-09-15 09:46:25,575 | There is no customer defined id or cdk path defined for resource UploadBucket, so we will use the resource logical id as the resource
id                                                                                                                                                             
2025-09-15 09:46:25,576 | Sam customer defined id is more priority than other IDs. Customer defined id for resource Function is Function                       
2025-09-15 09:46:25,576 | There is no customer defined id or cdk path defined for resource ProcessingBucket, so we will use the resource logical id as the     
resource id                                                                                                                                                    
2025-09-15 09:46:25,598 | There is no customer defined id or cdk path defined for resource UploadBucket, so we will use the resource logical id as the resource
id                                                                                                                                                             
2025-09-15 09:46:25,599 | Sam customer defined id is more priority than other IDs. Customer defined id for resource Function is Function                       
2025-09-15 09:46:25,599 | There is no customer defined id or cdk path defined for resource ProcessingBucket, so we will use the resource logical id as the     
resource id                                                                                                                                                    
2025-09-15 09:46:25,599 | Sam customer defined id is more priority than other IDs. Customer defined id for resource UploadBucket is UploadBucket               
2025-09-15 09:46:25,599 | Sam customer defined id is more priority than other IDs. Customer defined id for resource Function is Function                       
	Uploading to chapter03-stack/163ee584ab6b3cf65badd9ead77f026b  18205406 / 18205406  (100.00%)
2025-09-15 09:46:26,572 | Sam customer defined id is more priority than other IDs. Customer defined id for resource ProcessingBucket is ProcessingBucket       

	Deploying with following values
	===============================
	Stack name                   : chapter03-stack
	Region                       : ap-northeast-1
	Confirm changeset            : False
	Disable rollback             : False
	Deployment s3 bucket         : aws-sam-cli-managed-default-samclisourcebucket-5ae83a12
	Capabilities                 : ["CAPABILITY_IAM"]
	Parameter overrides          : {}
	Signing Profiles             : {}

Initiating deployment
=====================

2025-09-15 09:46:26,577 | No Parameters detected in the template                                                                                               
2025-09-15 09:46:26,583 | Sam customer defined id is more priority than other IDs. Customer defined id for resource UploadBucket is UploadBucket               
2025-09-15 09:46:26,583 | Sam customer defined id is more priority than other IDs. Customer defined id for resource Function is Function                       
2025-09-15 09:46:26,583 | Sam customer defined id is more priority than other IDs. Customer defined id for resource ProcessingBucket is ProcessingBucket       
2025-09-15 09:46:26,584 | 0 stacks found in the template                                                                                                       
2025-09-15 09:46:26,584 | No Parameters detected in the template                                                                                               
2025-09-15 09:46:26,589 | Sam customer defined id is more priority than other IDs. Customer defined id for resource UploadBucket is UploadBucket               
2025-09-15 09:46:26,589 | Sam customer defined id is more priority than other IDs. Customer defined id for resource Function is Function                       
2025-09-15 09:46:26,589 | Sam customer defined id is more priority than other IDs. Customer defined id for resource ProcessingBucket is ProcessingBucket       
2025-09-15 09:46:26,590 | 3 resources found in the stack                                                                                                       
2025-09-15 09:46:26,593 | Stack with id chapter03-stack does not exist                                                                                         
	Uploading to chapter03-stack/e14bb8c19f967e16a424506fde8c42b6.template  963 / 963  (100.00%)


Waiting for changeset to be created..

CloudFormation stack changeset
---------------------------------------------------------------------------------------------------------------------------------------------------------
Operation                              LogicalResourceId                      ResourceType                           Replacement                          
---------------------------------------------------------------------------------------------------------------------------------------------------------
+ Add                                  UploadBucket                           AWS::S3::Bucket                        N/A                                  
+ Add                                  ProcessingBucket                       AWS::S3::Bucket                        N/A                                  
+ Add                                  Function                               AWS::Lambda::Function                  N/A                                  
+ Add                                  FunctionRole                           AWS::IAM::Role                         N/A                                  
+ Add                                  FunctionUploadPermission               AWS::Lambda::Permission                N/A                                  
---------------------------------------------------------------------------------------------------------------------------------------------------------


Changeset created successfully. arn:aws:cloudformation:ap-northeast-1:000000000000:changeSet/samcli-deploy1757897186/bf9c397b


2025-09-15 09:46:26 - Waiting for stack create/update to complete

CloudFormation events from stack operations (refresh every 5.0 seconds)
---------------------------------------------------------------------------------------------------------------------------------------------------------
ResourceStatus                         ResourceType                           LogicalResourceId                      ResourceStatusReason                 
---------------------------------------------------------------------------------------------------------------------------------------------------------
2025-09-15 09:46:26,631 | Trial # 0 to get the stack chapter03-stack create events                                                                             
2025-09-15 09:46:31,638 | Stack Event: {'StackId': 'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId':             
'd6e4f0f4-3ee8-43d8-938d-d216b021ca69', 'StackName': 'chapter03-stack', 'LogicalResourceId': 'Function', 'PhysicalResourceId':                                 
'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'ResourceType': 'AWS::Lambda::Function', 'Timestamp':                     
datetime.datetime(2025, 9, 15, 0, 46, 26, 763000, tzinfo=tzutc()), 'ResourceStatus': 'CREATE_IN_PROGRESS'}                                                     
2025-09-15 09:46:31,639 | Stack Event: {'StackId': 'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId':             
'1dba36f8-e538-4e35-b7cd-346c0e65f222', 'StackName': 'chapter03-stack', 'LogicalResourceId': 'FunctionRole', 'PhysicalResourceId':                             
'chapter03-stack-FunctionRole-876101f3', 'ResourceType': 'AWS::IAM::Role', 'Timestamp': datetime.datetime(2025, 9, 15, 0, 46, 26, 742000, tzinfo=tzutc()),     
'ResourceStatus': 'CREATE_COMPLETE'}                                                                                                                           
2025-09-15 09:46:31,639 | Stack Event: {'StackId': 'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId':             
'9ad75046-7c52-44b1-a89b-27a0d8057d70', 'StackName': 'chapter03-stack', 'LogicalResourceId': 'FunctionRole', 'PhysicalResourceId':                             
'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'ResourceType': 'AWS::IAM::Role', 'Timestamp': datetime.datetime(2025, 9, 
15, 0, 46, 26, 627000, tzinfo=tzutc()), 'ResourceStatus': 'CREATE_IN_PROGRESS'}                                                                                
2025-09-15 09:46:31,640 | Stack Event: {'StackId': 'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId':             
'3ea58ce6-2d91-4593-8b9f-1ccec8c0db88', 'StackName': 'chapter03-stack', 'LogicalResourceId': 'ProcessingBucket', 'PhysicalResourceId':                         
'chapter03-processing-bucket', 'ResourceType': 'AWS::S3::Bucket', 'Timestamp': datetime.datetime(2025, 9, 15, 0, 46, 26, 597000, tzinfo=tzutc()),              
'ResourceStatus': 'CREATE_COMPLETE'}                                                                                                                           
2025-09-15 09:46:31,640 | Stack Event: {'StackId': 'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId':             
'2b9eb18d-13ad-4e38-8ff6-110a4329cc27', 'StackName': 'chapter03-stack', 'LogicalResourceId': 'ProcessingBucket', 'PhysicalResourceId':                         
'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'ResourceType': 'AWS::S3::Bucket', 'Timestamp': datetime.datetime(2025, 9,
15, 0, 46, 26, 594000, tzinfo=tzutc()), 'ResourceStatus': 'CREATE_IN_PROGRESS'}                                                                                
2025-09-15 09:46:31,641 | Stack Event: {'StackId': 'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId':             
'0d412de8-99ca-479a-90f6-166bbf3a90e4', 'StackName': 'chapter03-stack', 'LogicalResourceId': 'chapter03-stack', 'PhysicalResourceId':                          
'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'ResourceType': 'AWS::CloudFormation::Stack', 'Timestamp':                
datetime.datetime(2025, 9, 15, 0, 46, 26, 589000, tzinfo=tzutc()), 'ResourceStatus': 'CREATE_IN_PROGRESS'}                                                     
2025-09-15 09:46:31,642 | Stack Event: {'StackId': 'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId':             
'6b474805-4a91-4ce5-bc51-e1c6a88a73aa', 'StackName': 'chapter03-stack', 'LogicalResourceId': 'chapter03-stack', 'PhysicalResourceId':                          
'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'ResourceType': 'AWS::CloudFormation::Stack', 'Timestamp':                
datetime.datetime(2025, 9, 15, 0, 46, 26, 561000, tzinfo=tzutc()), 'ResourceStatus': 'REVIEW_IN_PROGRESS'}                                                     
2025-09-15 09:46:31,642 | Skip previous event as time_stamp_marker: 2025-09-15 00:46:26.561000 is after the event time stamp: 2025-09-15 00:46:26.561000+00:00 
2025-09-15 09:46:31,643 | Exit from the describe event loop                                                                                                    
CREATE_IN_PROGRESS                     AWS::CloudFormation::Stack             chapter03-stack                        -                                    
CREATE_IN_PROGRESS                     AWS::S3::Bucket                        ProcessingBucket                       -                                    
CREATE_COMPLETE                        AWS::S3::Bucket                        ProcessingBucket                       -                                    
CREATE_IN_PROGRESS                     AWS::IAM::Role                         FunctionRole                           -                                    
CREATE_COMPLETE                        AWS::IAM::Role                         FunctionRole                           -                                    
CREATE_IN_PROGRESS                     AWS::Lambda::Function                  Function                               -                                    
2025-09-15 09:46:31,643 | Trial # 0 to get the stack chapter03-stack create events                                                                             
2025-09-15 09:46:36,658 | Stack Event: {'StackId': 'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId':             
'd6e4f0f4-3ee8-43d8-938d-d216b021ca69', 'StackName': 'chapter03-stack', 'LogicalResourceId': 'Function', 'PhysicalResourceId':                                 
'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'ResourceType': 'AWS::Lambda::Function', 'Timestamp':                     
datetime.datetime(2025, 9, 15, 0, 46, 26, 763000, tzinfo=tzutc()), 'ResourceStatus': 'CREATE_IN_PROGRESS'}                                                     
2025-09-15 09:46:36,660 | Skip previous event as time_stamp_marker: 2025-09-15 00:46:26.763000 is after the event time stamp: 2025-09-15 00:46:26.763000+00:00 
2025-09-15 09:46:36,661 | Exit from the describe event loop                                                                                                    
2025-09-15 09:46:36,661 | Trial # 0 to get the stack chapter03-stack create events                                                                             
2025-09-15 09:46:41,678 | Stack Event: {'StackId': 'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId':             
'59a11aa6-e95f-4a74-88e7-208b43e0ef0a', 'StackName': 'chapter03-stack', 'LogicalResourceId': 'chapter03-stack', 'PhysicalResourceId':                          
'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'ResourceType': 'AWS::CloudFormation::Stack', 'Timestamp':                
datetime.datetime(2025, 9, 15, 0, 46, 37, 98000, tzinfo=tzutc()), 'ResourceStatus': 'CREATE_COMPLETE'}                                                         
2025-09-15 09:46:41,680 | Stack Event: {'StackId': 'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId':             
'a3e7ff3f-f82d-4384-83a6-26d9653ac06c', 'StackName': 'chapter03-stack', 'LogicalResourceId': 'UploadBucket', 'PhysicalResourceId': 'chapter03-upload-bucket',  
'ResourceType': 'AWS::S3::Bucket', 'Timestamp': datetime.datetime(2025, 9, 15, 0, 46, 37, 98000, tzinfo=tzutc()), 'ResourceStatus': 'CREATE_COMPLETE'}         
2025-09-15 09:46:41,681 | Stack Event: {'StackId': 'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId':             
'72dbb303-8d80-47e7-98ae-de1e6eafff1f', 'StackName': 'chapter03-stack', 'LogicalResourceId': 'UploadBucket', 'PhysicalResourceId':                             
'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'ResourceType': 'AWS::S3::Bucket', 'Timestamp': datetime.datetime(2025, 9,
15, 0, 46, 37, 83000, tzinfo=tzutc()), 'ResourceStatus': 'CREATE_IN_PROGRESS'}                                                                                 
2025-09-15 09:46:41,682 | Stack Event: {'StackId': 'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId':             
'149d2c37-e0f1-4351-bf9d-df073263ea02', 'StackName': 'chapter03-stack', 'LogicalResourceId': 'FunctionUploadPermission', 'PhysicalResourceId':                 
'chapter03-stack-FunctionUploadPermission-78ae60c0', 'ResourceType': 'AWS::Lambda::Permission', 'Timestamp': datetime.datetime(2025, 9, 15, 0, 46, 37, 57000,  
tzinfo=tzutc()), 'ResourceStatus': 'CREATE_COMPLETE'}                                                                                                          
2025-09-15 09:46:41,683 | Stack Event: {'StackId': 'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId':             
'74ae5b8e-c44b-4d9b-ada3-c7c486f9feff', 'StackName': 'chapter03-stack', 'LogicalResourceId': 'FunctionUploadPermission', 'PhysicalResourceId':                 
'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'ResourceType': 'AWS::Lambda::Permission', 'Timestamp':                   
datetime.datetime(2025, 9, 15, 0, 46, 37, 55000, tzinfo=tzutc()), 'ResourceStatus': 'CREATE_IN_PROGRESS'}                                                      
2025-09-15 09:46:41,685 | Stack Event: {'StackId': 'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId':             
'e9af580f-76a9-419b-947e-8bd10d87dfbf', 'StackName': 'chapter03-stack', 'LogicalResourceId': 'Function', 'PhysicalResourceId': 'chapter03-function',           
'ResourceType': 'AWS::Lambda::Function', 'Timestamp': datetime.datetime(2025, 9, 15, 0, 46, 37, 28000, tzinfo=tzutc()), 'ResourceStatus': 'CREATE_COMPLETE'}   
2025-09-15 09:46:41,686 | Stack Event: {'StackId': 'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId':             
'd6e4f0f4-3ee8-43d8-938d-d216b021ca69', 'StackName': 'chapter03-stack', 'LogicalResourceId': 'Function', 'PhysicalResourceId':                                 
'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'ResourceType': 'AWS::Lambda::Function', 'Timestamp':                     
datetime.datetime(2025, 9, 15, 0, 46, 26, 763000, tzinfo=tzutc()), 'ResourceStatus': 'CREATE_IN_PROGRESS'}                                                     
2025-09-15 09:46:41,687 | Skip previous event as time_stamp_marker: 2025-09-15 00:46:26.763000 is after the event time stamp: 2025-09-15 00:46:26.763000+00:00 
2025-09-15 09:46:41,688 | Exit from the describe event loop                                                                                                    
CREATE_COMPLETE                        AWS::Lambda::Function                  Function                               -                                    
CREATE_IN_PROGRESS                     AWS::Lambda::Permission                FunctionUploadPermission               -                                    
CREATE_COMPLETE                        AWS::Lambda::Permission                FunctionUploadPermission               -                                    
CREATE_IN_PROGRESS                     AWS::S3::Bucket                        UploadBucket                           -                                    
CREATE_COMPLETE                        AWS::S3::Bucket                        UploadBucket                           -                                    
CREATE_COMPLETE                        AWS::CloudFormation::Stack             chapter03-stack                        -                                    
2025-09-15 09:46:41,688 | Stack chapter03-stack is not in progress. Its status is CREATE_COMPLETE, and event is {'StackId':                                    
'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'EventId': '59a11aa6-e95f-4a74-88e7-208b43e0ef0a', 'StackName':           
'chapter03-stack', 'LogicalResourceId': 'chapter03-stack', 'PhysicalResourceId':                                                                               
'arn:aws:cloudformation:ap-northeast-1:000000000000:stack/chapter03-stack/2f8d0ab3', 'ResourceType': 'AWS::CloudFormation::Stack', 'Timestamp':                
datetime.datetime(2025, 9, 15, 0, 46, 37, 98000, tzinfo=tzutc()), 'ResourceStatus': 'CREATE_COMPLETE'}                                                         
---------------------------------------------------------------------------------------------------------------------------------------------------------


Successfully created/updated stack - chapter03-stack in ap-northeast-1

2025-09-15 09:46:41,699 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics                           
2025-09-15 09:46:41,749 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics                           
2025-09-15 09:46:41,750 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '1818f68c-ce8e-463a-89da-bbb6b4860423', 'installationId':               
'6231ce56-f8c3-4d62-9c54-1da1c88b62a3', 'sessionId': '5196c176-f438-4fd8-8586-fb4547b643c2', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.13.7',
'samcliVersion': '1.144.0', 'awsProfileProvided': True, 'debugFlagProvided': True, 'region': 'ap-northeast-1', 'commandName': 'sam deploy',                    
'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName': '644de0f55ae1ee73ef08416767d4d71b0d374c1029fa316c55bab791b790551c',       
'initialCommit': None, 'containerEngine': 'docker-default'}, 'duration': 31448, 'exitReason': 'success', 'exitCode': 0}}]}                                     
2025-09-15 09:46:41,750 | Unable to find Click Context for getting session_id.                                                                                 
2025-09-15 09:46:41,751 | Sending Telemetry: {'metrics': [{'events': {'requestId': '6db9146f-d5f9-40a5-bfec-7034fbebc3b7', 'installationId':                   
'6231ce56-f8c3-4d62-9c54-1da1c88b62a3', 'sessionId': '5196c176-f438-4fd8-8586-fb4547b643c2', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.13.7',
'samcliVersion': '1.144.0', 'commandName': 'sam deploy', 'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value':       
'.toml', 'thread_id': '8b895d3fe4b9425fb8701005319de1d3', 'time_stamp': '2025-09-15 00:46:10.233', 'exception_name': None}, {'event_name':                     
'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '081936f01a1b430c8f3a1b41393e15fa', 'time_stamp': '2025-09-15 00:46:10.250', 'exception_name':  
None}], 'containerEngine': 'docker-default'}}}]}                                                                                                               
2025-09-15 09:46:42,374 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)     
2025-09-15 09:46:42,376 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)     

デプロイに成功したようなので、Chapter 03のサンプルを実行してみます。

$ awslocal s3api put-object --bucket chapter03-upload-bucket --key Arch_AWS-Lambda_64.png --body ./images/Arch_AWS-Lambda_64.png 

実行結果として以下の表示がされました。

{
    "ETag": "\"37795d20eedf6eca67157120534da2c2\"",
    "ChecksumCRC64NVME": "eS942q1yTk4=",
    "ChecksumType": "FULL_OBJECT",
    "ServerSideEncryption": "AES256"
}

ファイルがアップロードされているか確認します。

$ aws s3 ls --endpoint-url=http://localhost:4566 chapter03-upload-bucket --profile localstack
2025-09-15 09:56:36       2423 Arch_AWS-Lambda_64.png

データはアップロードされているようです。
ダウンロードもできました。

$ aws s3 cp s3://chapter03-upload-bucket/Arch_AWS-Lambda_64.png . --endpoint-url=http://localhost:4566 --profile localstack
download: s3://chapter03-upload-bucket/Arch_AWS-Lambda_64.png to ./Arch_AWS-Lambda_64.png

グレースケールに変換されているか確認します。

$ aws s3 ls --endpoint-url=http://localhost:4566 chapter03-processing-bucket --profile localstack
2025-09-15 09:56:36       2423 Arch_AWS-Lambda_64.png

データはアップロードされているようです。
ダウンロードもできました。

$ aws s3 cp s3://chapter03-processing-bucket/gray-scale-Arch_AWS-Lambda_64.png . --endpoint-url=http://localhost:4566 --profile localstack
download: s3://chapter03-upload-bucket/Arch_AWS-Lambda_64.png to ./Arch_AWS-Lambda_64.png

colimaの起動から終了まで

色々とエラーを対処したりしたので、最初から最後までエラーなしで実行した実行結果を記載しておきます。

% colima start
INFO[0001] starting colima                              
INFO[0001] runtime: docker                              
INFO[0003] starting ...                                  context=vm
INFO[0014] provisioning ...                              context=docker
INFO[0015] starting ...                                  context=docker
INFO[0016] done                                         
$ localstack start -d

     __                     _______ __             __
    / /   ____  _________ _/ / ___// /_____ ______/ /__
   / /   / __ \/ ___/ __ `/ /\__ \/ __/ __ `/ ___/ //_/
  / /___/ /_/ / /__/ /_/ / /___/ / /_/ /_/ / /__/ ,<
 /_____/\____/\___/\__,_/_//____/\__/\__,_/\___/_/|_|

- LocalStack CLI: 4.7.0
- Profile: default
- App: https://app.localstack.cloud

[14:24:33] starting LocalStack in Docker mode 🐳                                                        localstack.py:532
           preparing environment                                                                        bootstrap.py:1309
           configuring container                                                                        bootstrap.py:1317
           starting container                                                                           bootstrap.py:1327
           detaching                                                                                    bootstrap.py:1331
$ sam build
Building codeuri: /Users/nomura/localstack/aws-serverless-pattern-workshop-using-localstack/chapter03/src runtime:       
python3.13 architecture: x86_64 functions: Function                                                                      
 Running PythonPipBuilder:ResolveDependencies                                                                            
 Running PythonPipBuilder:CopySource                                                                                     

Build Succeeded

Built Artifacts  : .aws-sam/build
Built Template   : .aws-sam/build/template.yaml

Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke
[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
[*] Deploy: sam deploy --guided
$ export AWS_ENDPOINT_URL=http://localhost:4566
$ sam deploy                                   
	Creating the required resources...
	Successfully created!

	Managed S3 bucket: aws-sam-cli-managed-default-samclisourcebucket-d1662de8
	Auto resolution of buckets can be turned off by setting resolve_s3=False
	To use a specific S3 bucket, set --s3-bucket=<bucket_name>
	Above settings can be stored in samconfig.toml
	Uploading to chapter03-stack/163ee584ab6b3cf65badd9ead77f026b  18205406 / 18205406  (100.00%)

	Deploying with following values
	===============================
	Stack name                   : chapter03-stack
	Region                       : ap-northeast-1
	Confirm changeset            : False
	Disable rollback             : False
	Deployment s3 bucket         : aws-sam-cli-managed-default-samclisourcebucket-d1662de8
	Capabilities                 : ["CAPABILITY_IAM"]
	Parameter overrides          : {}
	Signing Profiles             : {}

Initiating deployment
=====================

	Uploading to chapter03-stack/2aeae131fc5b1d517195bf60e773f63d.template  963 / 963  (100.00%)


Waiting for changeset to be created..

CloudFormation stack changeset
---------------------------------------------------------------------------------------------------------------------
Operation                     LogicalResourceId             ResourceType                  Replacement                 
---------------------------------------------------------------------------------------------------------------------
+ Add                         UploadBucket                  AWS::S3::Bucket               N/A                         
+ Add                         ProcessingBucket              AWS::S3::Bucket               N/A                         
+ Add                         Function                      AWS::Lambda::Function         N/A                         
+ Add                         FunctionRole                  AWS::IAM::Role                N/A                         
+ Add                         FunctionUploadPermission      AWS::Lambda::Permission       N/A                         
---------------------------------------------------------------------------------------------------------------------


Changeset created successfully. arn:aws:cloudformation:ap-northeast-1:000000000000:changeSet/samcli-deploy1758346019/4bea6f6e


2025-09-20 14:26:59 - Waiting for stack create/update to complete

CloudFormation events from stack operations (refresh every 5.0 seconds)
---------------------------------------------------------------------------------------------------------------------
ResourceStatus                ResourceType                  LogicalResourceId             ResourceStatusReason        
---------------------------------------------------------------------------------------------------------------------
CREATE_IN_PROGRESS            AWS::CloudFormation::Stack    chapter03-stack               -                           
CREATE_IN_PROGRESS            AWS::S3::Bucket               ProcessingBucket              -                           
CREATE_COMPLETE               AWS::S3::Bucket               ProcessingBucket              -                           
CREATE_IN_PROGRESS            AWS::IAM::Role                FunctionRole                  -                           
CREATE_COMPLETE               AWS::IAM::Role                FunctionRole                  -                           
CREATE_IN_PROGRESS            AWS::Lambda::Function         Function                      -                           
CREATE_COMPLETE               AWS::Lambda::Function         Function                      -                           
CREATE_IN_PROGRESS            AWS::Lambda::Permission       FunctionUploadPermission      -                           
CREATE_COMPLETE               AWS::Lambda::Permission       FunctionUploadPermission      -                           
CREATE_IN_PROGRESS            AWS::S3::Bucket               UploadBucket                  -                           
CREATE_COMPLETE               AWS::S3::Bucket               UploadBucket                  -                           
CREATE_COMPLETE               AWS::CloudFormation::Stack    chapter03-stack               -                           
---------------------------------------------------------------------------------------------------------------------


Successfully created/updated stack - chapter03-stack in ap-northeast-1

$ awslocal s3api put-object --bucket chapter03-upload-bucket --key Arch_AWS-Lambda_64.png --body ./images/Arch_AWS-Lambda_64.png
{
    "ETag": "\"37795d20eedf6eca67157120534da2c2\"",
    "ChecksumCRC64NVME": "eS942q1yTk4=",
    "ChecksumType": "FULL_OBJECT",
    "ServerSideEncryption": "AES256"
}
$ aws s3 ls --endpoint-url=http://localhost:4566 chapter03-upload-bucket --profile localstack
2025-09-20 14:27:47       2423 Arch_AWS-Lambda_64.png
$ aws s3 cp s3://chapter03-upload-bucket/Arch_AWS-Lambda_64.png . --endpoint-url=http://localhost:4566 --profile localstack
download: s3://chapter03-upload-bucket/Arch_AWS-Lambda_64.png to ./Arch_AWS-Lambda_64.png
$ aws s3 ls --endpoint-url=http://localhost:4566 chapter03-processing-bucket --profile localstack
2025-09-20 14:27:49       1029 gray-scale-Arch_AWS-Lambda_64.png
$ aws s3 cp s3://chapter03-processing-bucket/gray-scale-Arch_AWS-Lambda_64.png . --endpoint-url=http://localhost:4566 --profile localstack
download: s3://chapter03-processing-bucket/gray-scale-Arch_AWS-Lambda_64.png to ./gray-scale-Arch_AWS-Lambda_64.png
$ localstack stop
container stopped: localstack-main
$ colima stop
INFO[0000] stopping colima                              
INFO[0001] stopping ...                                  context=docker
INFO[0002] stopping ...                                  context=vm
INFO[0004] done                                         

修正したsamconfig.toml

samconfig.toml
version = 0.1
[default.deploy.parameters]
stack_name = "chapter03-stack"
resolve_s3 = true
endpoint_url = "http://localhost:4566"
s3_prefix = "chapter03-stack"
region = "ap-northeast-1"
capabilities = "CAPABILITY_IAM"
image_repositories = []
profile = "localstack"

ダウンロードしたファイル

Arch_AWS-Lambda_64.png
Arch_AWS-Lambda_64.png
gray-scale-Arch_AWS-Lambda_64.png
gray-scale-Arch_AWS-Lambda_64.png

最後に

今回は、参考にしたLocalStack 実践入門 | AWS サーバレスパターン開発ワークショップに記載されていたGitHub Codespacesではなく、前回自分で作った環境(Colima+Localstack)を使って試行錯誤しながらワークショップに記載されていた「画像処理、シンプルなデータ加工」サーバレスパターンを試してみて、カラーのアイコンをグレースケールのアイコンに変換してみてみました。
また、LocalStack Resource Browserも使わなかったので、LocalStackのS3からPNGのアイコンをダウンロードするところまで実施しました。

LocalStackの詳細や「画像処理、シンプルなデータ加工」サーバレスパターンの処理の内容などは本家の以下のWebページを参照ください。
とてもわかりやすく書かれています。

カックさん、良書をありがとうございます!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?