Use Output.json_dumps
MODIFY
aws-py-apigateway-lambda-serverless/__main__.py
aws-py-apigateway-lambda-serverless/__main__.py
"""An AWS Python Pulumi program"""
+import iam
import pulumi
import pulumi_aws as aws
-import iam
-import json
region = aws.config.region
@@ -37,7 +36,7 @@ def swagger_route_handler(arn):
return ({
"x-amazon-apigateway-any-method": {
"x-amazon-apigateway-integration": {
- "uri": f'arn:aws:apigateway:{region}:lambda:path/2015-03-31/functions/{arn}/invocations',
+ "uri": pulumi.Output.format('arn:aws:apigateway:{0}:lambda:path/2015-03-31/functions/{1}/invocations', region, arn),
"passthroughBehavior": "when_no_match",
"httpMethod": "POST",
"type": "aws_proxy",
@@ -47,13 +46,13 @@ def swagger_route_handler(arn):
# Create the API Gateway Rest API, using a swagger spec.
rest_api = aws.apigateway.RestApi("api",
- body=lambda_func.arn.apply(lambda arn: json.dumps({
+ body=pulumi.Output.json_dumps({
"swagger": "2.0",
"info": {"title": "api", "version": "1.0"},
"paths": {
- "/{proxy+}": swagger_route_handler(arn),
+ "/{proxy+}": swagger_route_handler(lambda_func.arn),
},
- })))
+ }))
# Create a deployment of the Rest API.
deployment = aws.apigateway.Deployment("api-deployment",

MODIFY
aws-py-appsync/__main__.py
aws-py-appsync/__main__.py
import json
+
import pulumi_random as random
-from pulumi import export
-from pulumi_aws import dynamodb, iam, appsync
+from pulumi import Output, export
+from pulumi_aws import appsync, dynamodb, iam
## Dynamo DB table to hold data for the GraphQL endpoint
table = dynamodb.Table(
@@ -30,7 +31,7 @@ role = iam.Role(
policy = iam.Policy(
"iam-policy",
- policy=table.arn.apply(lambda arn: json.dumps({
+ policy= Output.json_dumps({
"Version": "2012-10-17",
"Statement": [{
"Action": [
@@ -38,9 +39,9 @@ policy = iam.Policy(
"dynamodb:GetItem"
],
"Effect": "Allow",
- "Resource": [arn]
+ "Resource": [table.arn]
}]
- })))
+ }))
attachment = iam.RolePolicyAttachment(
"iam-policy-attachment",

MODIFY
aws-py-assume-role/create-role/__main__.py
aws-py-assume-role/create-role/__main__.py
# Copyright 2016-2020, Pulumi Corporation. All rights reserved.
-import pulumi_aws as aws
import json
-from pulumi import Config, ResourceOptions, export
+
+import pulumi_aws as aws
+from pulumi import Config, Output, ResourceOptions, export
def assume_role_policy_for_principal(principal):
@@ -11,7 +12,7 @@ def assume_role_policy_for_principal(principal):
which can be used to control which principals may assume an IAM Role, by
granting the `sts:AssumeRole` action to those principals.
"""
- return json.dumps({
+ return Output.json_dumps({
'Version': '2012-10-17',
'Statement': [
{
@@ -42,9 +43,7 @@ unprivileged_user_creds = aws.iam.AccessKey(
allow_s3_management_role = aws.iam.Role('allow-s3-management',
description='Allow management of S3 buckets',
- assume_role_policy=unprivileged_user.arn.apply(lambda arn:
- assume_role_policy_for_principal({'AWS': arn})
- )
+ assume_role_policy=assume_role_policy_for_principal({'AWS': unprivileged_user.arn})
)
policy = aws.iam.RolePolicy('allow-s3-management-policy',

MODIFY
aws-py-django-voting-app/__main__.py
aws-py-django-voting-app/__main__.py
# Copyright 2016-2020, Pulumi Corporation. All rights reserved.
-import json
import base64
+import json
+
import pulumi
import pulumi_aws as aws
import pulumi_docker as docker
@@ -255,18 +256,9 @@ django_database_task_definition = aws.ecs.TaskDefinition("django-database-task-d
requires_compatibilities=["FARGATE"],
execution_role_arn=app_exec_role.arn,
task_role_arn=app_task_role.arn,
- container_definitions=pulumi.Output.all(
- django_image.image_name,
- django_secret_key,
- mysql_database.name,
- sql_admin_name,
- sql_admin_password,
- django_admin_name,
- django_admin_password,
- mysql_rds_server.address,
- mysql_rds_server.port).apply(lambda args: json.dumps([{
+ container_definitions=pulumi.Output.json_dumps([{
"name": "django-container",
- "image": args[0],
+ "image": django_image.image_name,
"memory": 512,
"essential": True,
"portMappings": [{
@@ -275,14 +267,14 @@ django_database_task_definition = aws.ecs.TaskDefinition("django-database-task-d
"protocol": "tcp"
}],
"environment": [
- { "name": "SECRET_KEY", "value": args[1] },
- { "name": "DATABASE_NAME", "value": args[2] },
- { "name": "USER_NAME", "value": args[3] },
- { "name": "USER_PASSWORD", "value": args[4] },
- { "name": "DJANGO_NAME", "value": args[5] },
- { "name": "DJANGO_PASSWORD", "value": args[6] },
- { "name": "DATABASE_ADDRESS", "value": args[7] },
- { "name": "DATABASE_PORT", "value": str(int(args[8])) },
+ { "name": "SECRET_KEY", "value": django_secret_key },
+ { "name": "DATABASE_NAME", "value": mysql_database.name },
+ { "name": "USER_NAME", "value": sql_admin_name },
+ { "name": "USER_PASSWORD", "value": sql_admin_password },
+ { "name": "DJANGO_NAME", "value": django_admin_name },
+ { "name": "DJANGO_PASSWORD", "value": django_admin_password },
+ { "name": "DATABASE_ADDRESS", "value": mysql_rds_server.address },
+ { "name": "DATABASE_PORT", "value": mysql_rds_server.port.apply(lambda x: str(int(x))) },
],
"logConfiguration": {
"logDriver": "awslogs",
@@ -293,7 +285,7 @@ django_database_task_definition = aws.ecs.TaskDefinition("django-database-task-d
},
},
"command": ["/mysite/setupDatabase.sh"]
- }])))
+ }]))
# Launching our Django service on Fargate, using our configurations and load balancers
django_database_service = aws.ecs.Service("django-database-service",
@@ -325,16 +317,9 @@ django_site_task_definition = aws.ecs.TaskDefinition("django-site-task-definitio
requires_compatibilities=["FARGATE"],
execution_role_arn=app_exec_role.arn,
task_role_arn=app_task_role.arn,
- container_definitions=pulumi.Output.all(
- django_image.image_name,
- django_secret_key,
- mysql_database.name,
- sql_user_name,
- sql_user_password,
- mysql_rds_server.address,
- mysql_rds_server.port).apply(lambda args: json.dumps([{
+ container_definitions=pulumi.Output.json_dumps([{
"name": "django-container",
- "image": args[0],
+ "image": django_image.image_name,
"memory": 512,
"essential": True,
"portMappings": [{
@@ -343,12 +328,12 @@ django_site_task_definition = aws.ecs.TaskDefinition("django-site-task-definitio
"protocol": "tcp"
}],
"environment": [
- { "name": "SECRET_KEY", "value": args[1] },
- { "name": "DATABASE_NAME", "value": args[2] },
- { "name": "USER_NAME", "value": args[3] },
- { "name": "USER_PASSWORD", "value": args[4] },
- { "name": "DATABASE_ADDRESS", "value": args[5] },
- { "name": "DATABASE_PORT", "value": str(int(args[6])) },
+ { "name": "SECRET_KEY", "value": django_secret_key },
+ { "name": "DATABASE_NAME", "value": mysql_database.name },
+ { "name": "USER_NAME", "value": sql_user_name },
+ { "name": "USER_PASSWORD", "value": sql_user_password },
+ { "name": "DATABASE_ADDRESS", "value": mysql_rds_server.address },
+ { "name": "DATABASE_PORT", "value": mysql_rds_server.port.apply(lambda x: str(int(x))) },
],
"logConfiguration": {
"logDriver": "awslogs",
@@ -358,7 +343,7 @@ django_site_task_definition = aws.ecs.TaskDefinition("django-site-task-definitio
"awslogs-stream-prefix": "djangoApp-site",
},
},
- }])))
+ }]))
# Launching our Django service on Fargate, using our configurations and load balancers
django_site_service = aws.ecs.Service("django-site-service",

MODIFY
aws-py-eks/utils.py
aws-py-eks/utils.py
import json
+
import pulumi
+
def generate_kube_config(eks_cluster):
- kubeconfig = pulumi.Output.all(eks_cluster.endpoint, eks_cluster.certificate_authority.apply(lambda v: v.data), eks_cluster.name).apply(lambda args: json.dumps({
+ kubeconfig = pulumi.Output.json_dumps({
"apiVersion": "v1",
"clusters": [{
"cluster": {
- "server": args[0],
- "certificate-authority-data": args[1]
+ "server": eks_cluster.endpoint,
+ "certificate-authority-data": eks_cluster.certificate_authority.apply(lambda v: v.data)
},
"name": "kubernetes",
}],
@@ -30,10 +32,10 @@ def generate_kube_config(eks_cluster):
"args": [
"token",
"-i",
- args[2],
+ eks_cluster.endpoint,
],
},
},
}],
- }))
+ })
return kubeconfig

MODIFY
aws-py-s3-folder/__main__.py
aws-py-s3-folder/__main__.py
@@ -2,7 +2,7 @@ import json
import mimetypes
import os
-from pulumi import export, FileAsset
+from pulumi import FileAsset, Output, export
from pulumi_aws import s3
web_bucket = s3.Bucket('s3-website-bucket',
@@ -20,7 +20,7 @@ for file in os.listdir(content_dir):
content_type=mime_type)
def public_read_policy_for_bucket(bucket_name):
- return json.dumps({
+ return Output.json_dumps({
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
@@ -29,7 +29,7 @@ def public_read_policy_for_bucket(bucket_name):
"s3:GetObject"
],
"Resource": [
- f"arn:aws:s3:::{bucket_name}/*",
+ Output.format("arn:aws:s3:::{0}/*", bucket_name),
]
}]
})
@@ -37,7 +37,7 @@ def public_read_policy_for_bucket(bucket_name):
bucket_name = web_bucket.id
bucket_policy = s3.BucketPolicy("bucket-policy",
bucket=bucket_name,
- policy=bucket_name.apply(public_read_policy_for_bucket))
+ policy=public_read_policy_for_bucket(bucket_name))
# Export the name of the bucket
export('bucket_name', web_bucket.id)

MODIFY
aws-py-serverless-raw/__main__.py
aws-py-serverless-raw/__main__.py
@@ -50,19 +50,19 @@ role = aws.iam.Role("mylambda-role",
policy = aws.iam.RolePolicy("mylambda-policy",
role=role.id,
- policy=counter_table.arn.apply(lambda arn: json.dumps({
+ policy=pulumi.Output.json_dumps({
"Version": "2012-10-17",
"Statement": [{
"Action": ["dynamodb:UpdateItem", "dynamodb:PutItem", "dynamodb:GetItem",
"dynamodb:DescribeTable"],
- "Resource": arn,
+ "Resource": counter_table.arn,
"Effect": "Allow",
}, {
"Action": ["logs:*", "cloudwatch:*"],
"Resource": "*",
"Effect": "Allow",
}],
- })))
+ }))
# Read the config of whether to provision fixed concurrency for Lambda
config = pulumi.Config()
@@ -105,7 +105,7 @@ def swagger_route_handler(arn):
return ({
"x-amazon-apigateway-any-method": {
"x-amazon-apigateway-integration": {
- "uri": f'arn:aws:apigateway:{region}:lambda:path/2015-03-31/functions/{arn}/invocations',
+ "uri": pulumi.Output.format('arn:aws:apigateway:{0}:lambda:path/2015-03-31/functions/{1}/invocations', region, arn),
"passthroughBehavior": "when_no_match",
"httpMethod": "POST",
"type": "aws_proxy",
@@ -115,13 +115,13 @@ def swagger_route_handler(arn):
# Create the API Gateway Rest API, using a swagger spec.
rest_api = aws.apigateway.RestApi("api",
- body=lambda_func.arn.apply(lambda arn: json.dumps({
+ body=pulumi.Output.json_dumps({
"swagger": "2.0",
"info": {"title": "api", "version": "1.0"},
"paths": {
- "/{proxy+}": swagger_route_handler(arn),
+ "/{proxy+}": lambda_func.arn.apply(swagger_route_handler),
},
- })))
+ }))
# Create a deployment of the Rest API.
deployment = aws.apigateway.Deployment("api-deployment",

MODIFY
aws-py-slackbot/__main__.py
aws-py-slackbot/__main__.py
# re -> regular expression package
-import re
+import base64
import json
+import re
+
import boto3
import iam
-import base64
import pulumi
import pulumi_aws as aws
@@ -83,7 +84,7 @@ def swagger_route_handler(arn):
return ({
"x-amazon-apigateway-any-method": {
"x-amazon-apigateway-integration": {
- "uri": f'arn:aws:apigateway:{region}:lambda:path/2015-03-31/functions/{arn}/invocations',
+ "uri": pulumi.Output.format('arn:aws:apigateway:{0}:lambda:path/2015-03-31/functions/{1}/invocations', region, arn),
"passthroughBehavior": "when_no_match",
"httpMethod": "POST",
"type": "aws_proxy",
@@ -93,13 +94,13 @@ def swagger_route_handler(arn):
# Create the API Gateway Rest API, using a swagger spec.
rest_api = aws.apigateway.RestApi("mentionbot",
- body=lambda_func.arn.apply(lambda arn: json.dumps({
+ body=pulumi.Output.json_dumps({
"swagger": "2.0",
"info": {"title": "slackbot-webhooks", "version": "1.0"},
"paths": {
- "/{proxy+}": swagger_route_handler(arn),
+ "/{proxy+}": swagger_route_handler(lambda_func.arn),
},
- })))
+ }))
# Create a deployment of the Rest API.
deployment = aws.apigateway.Deployment("api-deployment",

MODIFY
aws-py-voting-app/__main__.py
aws-py-voting-app/__main__.py
# Copyright 2016-2020, Pulumi Corporation. All rights reserved.
-import json
import base64
+import json
+
import pulumi
import pulumi_aws as aws
import pulumi_docker as docker
@@ -254,9 +255,9 @@ flask_task_definition = aws.ecs.TaskDefinition("flask-task-definition",
requires_compatibilities=["FARGATE"],
execution_role_arn=app_exec_role.arn,
task_role_arn=app_task_role.arn,
- container_definitions=pulumi.Output.all(flask_image.image_name, redis_endpoint).apply(lambda args: json.dumps([{
+ container_definitions=pulumi.Output.json_dumps([{
"name": "flask-container",
- "image": args[0],
+ "image": flask_image.image_name,
"memory": 512,
"essential": True,
"portMappings": [{
@@ -265,11 +266,11 @@ flask_task_definition = aws.ecs.TaskDefinition("flask-task-definition",
"protocol": "tcp"
}],
"environment": [ # The Redis endpoint we created is given to Flask, allowing it to communicate with the former
- { "name": "REDIS", "value": args[1]["host"] },
- { "name": "REDIS_PORT", "value": str(args[1]["port"]) },
+ { "name": "REDIS", "value": redis_endpoint["host"] },
+ { "name": "REDIS_PORT", "value": redis_endpoint["port"].apply(lambda x: str(x)) },
{ "name": "REDIS_PWD", "value": redis_password },
],
- }])))
+ }]))
# Launching our Redis service on Fargate, using our configurations and load balancers
flask_service = aws.ecs.Service("flask-service",

MODIFY
aws-py-wordpress-fargate-rds/frontend.py
aws-py-wordpress-fargate-rds/frontend.py
-from pulumi import ComponentResource, ResourceOptions, Output
-import pulumi_aws as aws
import json
+import pulumi_aws as aws
+from pulumi import ComponentResource, Output, ResourceOptions
+
class WebServiceArgs:
@@ -95,9 +96,7 @@ class WebService(ComponentResource):
# Spin up a load balanced service running our container image.
task_name = f'{name}-app-task'
container_name = f'{name}-app-container'
- self.task_definition = Output.all(args.db_host, args.db_port, args.db_name, args.db_user, args.db_password).apply(
- lambda args:
- aws.ecs.TaskDefinition(task_name,
+ self.task_definition=aws.ecs.TaskDefinition(task_name,
family='fargate-task-definition',
cpu='256',
memory='512',
@@ -105,7 +104,7 @@ class WebService(ComponentResource):
requires_compatibilities=[
'FARGATE'],
execution_role_arn=role.arn,
- container_definitions=json.dumps([{
+ container_definitions=Output.json_dumps([{
'name': container_name,
'image': 'wordpress',
'portMappings': [{
@@ -116,25 +115,24 @@ class WebService(ComponentResource):
'environment': [
{
'name': 'WORDPRESS_DB_HOST',
- 'value': f'{args[0]}:{args[1]}'
+ 'value': Output.format("{0}:{1}", args.db_host, args.db_port)
},
{
'name': 'WORDPRESS_DB_NAME',
- 'value': f'{args[2]}'
+ 'value': args.db_name
},
{
'name': 'WORDPRESS_DB_USER',
- 'value': f'{args[3]}'
+ 'value': args.db_user
},
{
'name': 'WORDPRESS_DB_PASSWORD',
- 'value': f'{args[4]}'
+ 'value': args.db_password
},
]
}]),
opts=ResourceOptions(parent=self)
)
- )
self.service = aws.ecs.Service(f'{name}-app-svc',
cluster=self.cluster.arn,

Use Output.json_dumps (#1331)