Skip to content

Commit af651db

Browse files
authored
Fix build, invalid arn, and terraform deprecations (#204)
1 parent 7a467e6 commit af651db

File tree

6 files changed

+52
-27
lines changed

6 files changed

+52
-27
lines changed

ecs-ecr-container-app/Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ run: ## Build and deploy the app locally
1919
docker push "$$repoUri"; \
2020
docker rmi "$$repoUri"; \
2121
echo "Creating ECS infrastructure locally"; \
22-
awslocal cloudformation create-stack --stack-name infra --template-body file://templates/ecs.infra.yml; \
22+
awslocal cloudformation create-stack --stack-name infra --template-body file://templates/ecs.infra.yml && \
23+
awslocal cloudformation wait stack-create-complete --stack-name infra && \
2324
echo "Deploying ECS app to local environment"; \
24-
sleep 3 && awslocal cloudformation create-stack --stack-name sample \
25+
awslocal cloudformation create-stack --stack-name sample \
2526
--template-body file://templates/ecs.sample.yml \
2627
--parameters ParameterKey=ImageUrl,ParameterValue=$$repoUri && \
27-
echo "ECS app successfully deployed. Sleeping a bit, then trying to access the app endpoint." && \
28-
sleep 5 && \
28+
awslocal cloudformation wait stack-create-complete --stack-name sample && \
29+
echo "ECS app successfully deployed. Trying to access app endpoint." && \
2930
cluster_arn=$$(awslocal ecs list-clusters | jq -r '.clusterArns[0]') && \
3031
for i in {1..5}; do task_arn=$$(awslocal ecs list-tasks --cluster $$cluster_arn | jq -r '.taskArns[0]'); if [ "$$task_arn" != "null" ]; then break; fi; sleep 2; done && \
3132
for i in {1..5}; do app_port=$$(awslocal ecs describe-tasks --cluster $$cluster_arn --tasks $$task_arn | jq -r '.tasks[0].containers[0].networkBindings[0].hostPort'); if [ "$$app_port" != "null" ]; then break; fi; sleep 2; done && \

ecs-ecr-container-app/templates/ecs.infra.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,12 @@ Outputs:
287287
Name: !Join [ ':', [ !Ref 'AWS::StackName', 'VPCId' ] ]
288288
PublicSubnetOne:
289289
Description: Public subnet one
290-
# TODO
291-
# Value: !Ref 'PublicSubnetOne'
292-
Value: sub-123
290+
Value: !Ref 'PublicSubnetOne'
293291
Export:
294292
Name: !Join [ ':', [ !Ref 'AWS::StackName', 'PublicSubnetOne' ] ]
295293
PublicSubnetTwo:
296294
Description: Public subnet two
297-
# TODO
298-
# Value: !Ref 'PublicSubnetTwo'
299-
Value: sub-234
295+
Value: !Ref 'PublicSubnetTwo'
300296
Export:
301297
Name: !Join [ ':', [ !Ref 'AWS::StackName', 'PublicSubnetTwo' ] ]
302298
FargateContainerSecurityGroup:

lambda-container-image/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ run: ## Build, deploy, and invoke the Lambda container image locally
1717
docker rmi "$$repoUri"; \
1818
echo "Deploying Lambda function from container image locally"; \
1919
awslocal lambda create-function --function-name ls-lambda-image --package-type Image \
20-
--code ImageUri=$$repoUri --role arn:aws:iam::000000000:role/lambda-r1 \
20+
--code ImageUri=$$repoUri --role arn:aws:iam::000000000000:role/lambda-r1 \
2121
--handler handler.handler; \
22+
echo "Waiting until Lambda function becomes active"; \
23+
awslocal lambda wait function-active-v2 --function-name ls-lambda-image; \
2224
echo "Invoking Lambda function from container image"; \
23-
awslocal lambda invoke --function-name ls-lambda-image --payload '{"test":"test"}' /tmp/lambda.out; \
25+
awslocal lambda invoke --function-name ls-lambda-image --payload '{"test":"test"}' /tmp/lambda.out && \
2426
echo "Done - test successfully finished."
2527

2628
start:

lambda-container-image/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ Starting DNS server loop on UDP port 53
6262
Hello from LocalStack Lambda container image!
6363
```
6464

65+
## Troubleshooting
66+
67+
### UnsupportedMediaTypeException
68+
69+
```plain
70+
An error occurred (UnsupportedMediaTypeException) when calling the Invoke operation (reached max retries: 0): The payload is not JSON: b'\xb5\xeb-\xb5\xeb-'
71+
```
72+
73+
**Solution**: Downgrade your awslocal CLI to version 1 because invoking lambda functions differs in version 2 (see [major changes in aws cli](https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration-changes.html) and limitations of [awscli-local](https://github.com/localstack/awscli-local)) or update the lambda invocation:
74+
75+
```bash
76+
awslocal lambda invoke --cli-binary-format raw-in-base64-out --function-name ls-lambda-image --payload '{"test": "test"}' /tmp/lambda.out --log-type Tail --query 'LogResult' --output text | base64 -d
77+
```
78+
6579
## License
6680

6781
This code is available under the Apache 2.0 license.

terraform-resources/README.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,32 @@ You may need to confirm the creation by entering "yes". You should then see log
3939
4040
Enter a value: yes
4141
42+
Plan: 10 to add, 0 to change, 0 to destroy.
43+
aws_iam_role.invocation_role: Creating...
4244
aws_api_gateway_rest_api.demo: Creating...
4345
aws_iam_role.lambda: Creating...
44-
aws_iam_role.invocation_role: Creating...
46+
aws_db_parameter_group.default: Creating...
4547
aws_elasticache_cluster.my-redis: Creating...
46-
aws_s3_bucket.testBucket: Creating...
47-
aws_elasticsearch_domain.example: Creating...
48-
aws_iam_role.lambda: Creation complete after 0s [id=demo-lambda]
49-
aws_iam_role.invocation_role: Creation complete after 0s [id=api_gateway_auth_invocation]
50-
aws_lambda_function.authorizer: Creating...
51-
aws_api_gateway_rest_api.demo: Creation complete after 0s [id=fboao5ctp1]
48+
aws_s3_bucket.test-bucket: Creating...
49+
aws_api_gateway_rest_api.demo: Creation complete after 1s [id=iq0njx2s0a]
50+
aws_iam_role.invocation_role: Creation complete after 1s [id=api_gateway_auth_invocation]
51+
aws_iam_role.lambda: Creation complete after 1s [id=demo-lambda]
5252
aws_iam_role_policy.invocation_policy: Creating...
53-
aws_iam_role_policy.invocation_policy: Creation complete after 1s [id=api_gateway_auth_invocation:default]
54-
aws_s3_bucket.testBucket: Creation complete after 1s [id=myBucket]
55-
aws_lambda_function.authorizer: Creation complete after 6s [id=api_gateway_authorizer]
53+
aws_lambda_function.authorizer: Creating...
54+
aws_iam_role_policy.invocation_policy: Creation complete after 0s [id=api_gateway_auth_invocation:default]
55+
aws_s3_bucket.test-bucket: Creation complete after 2s [id=my-bucket]
56+
aws_s3_bucket_acl.test-bucket-acl: Creating...
57+
aws_s3_bucket_acl.test-bucket-acl: Creation complete after 0s [id=my-bucket,private]
58+
aws_db_parameter_group.default: Creation complete after 2s [id=rds-pg]
59+
aws_lambda_function.authorizer: Creation complete after 7s [id=api_gateway_authorizer]
5660
aws_api_gateway_authorizer.demo: Creating...
57-
aws_api_gateway_authorizer.demo: Creation complete after 0s [id=4dcdc808]
58-
...
59-
Apply complete! Resources: 9 added, 0 changed, 0 destroyed.
61+
aws_api_gateway_authorizer.demo: Creation complete after 0s [id=9a2570]
62+
aws_elasticache_cluster.my-redis: Still creating... [10s elapsed]
63+
aws_elasticache_cluster.my-redis: Still creating... [20s elapsed]
64+
aws_elasticache_cluster.my-redis: Still creating... [30s elapsed]
65+
aws_elasticache_cluster.my-redis: Creation complete after 32s [id=my-redis-cluster]
66+
67+
Apply complete! Resources: 10 added, 0 changed, 0 destroyed.
6068
```
6169

6270
## License

terraform-resources/test.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ provider "aws" {
22
access_key = "mock_access_key"
33
secret_key = "mock_secret_key"
44
region = "us-east-1"
5-
s3_force_path_style = true
5+
s3_use_path_style = true
66
skip_credentials_validation = true
77
skip_metadata_api_check = true
88
skip_requesting_account_id = true
@@ -35,7 +35,11 @@ provider "aws" {
3535

3636
resource "aws_s3_bucket" "test-bucket" {
3737
bucket = "my-bucket"
38-
acl = "private"
38+
}
39+
40+
resource "aws_s3_bucket_acl" "test-bucket-acl" {
41+
bucket = aws_s3_bucket.test-bucket.id
42+
acl = "private"
3943
}
4044

4145
resource "aws_api_gateway_authorizer" "demo" {

0 commit comments

Comments
 (0)