big-angle-30002
04/29/2024, 6:57 PMoai = OriginAccessIdentity(
f"OAI-{data_conf['project_name'].upper()}",
comment="OAI for allowing CloudFront to access the site S3 bucket")
which is perfectly created
oai = Output.all(oai.iam_arn, oai.s3_canonical_user_id).apply(
lambda args: print(f"OAI ARN: {args[0]} | OAI Canonical User ID: {args[1]}")
)
>>> OAI ARN: arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity E2HBZRUL9B8YD6 | OAI Canonical User ID: 6816a94df8576437bce079301fa206257850acd55849d905e19e13d4b942310f7646739fe2c756ae7e376c0fce7aaaf5
However, when I try to use these values ββin the policy document I get a NoneType error: AttributeError: 'NoneType' object has no attribute 's3_canonical_user_id'
my policy_document:
site_bucket_policies_statement = get_policy_document(
version="2012-10-17",
statements=[
{
"effect": "Deny",
"principals": [
{
"type": "AWS",
"identifiers": ["*"]
}
],
"actions": ["s3:*"],
"resources": [
site_bucket[0].arn.apply(lambda arn: arn),
],
"conditions": [
{
"test": "Bool",
"variable": "aws:SecureTransport",
"values": ["false"]
}
]
},
{
"effect": "Allow",
"actions": ["s3:GetObject"],
"resources": [
site_bucket[0].arn.apply(lambda arn: arn)
],
"principals": [{
"type": "AWS",
"identifiers": [ oai.s3_canonical_user_id.apply(lambda id: id)]
}]
},
{
"effect": "Allow",
"actions": [
"s3:PutBucketPolicy",
"s3:GetBucket*",
"s3:List*",
"s3:DeleteObject*"
],
"resources": [
site_bucket[0].arn.apply(lambda arn: arn)
],
"principals": [{
"type": "AWS",
"identifiers": [ lambda_role.arn.apply(lambda arn: arn) ]
}]
}
]
)
and the Bucket Policy creation:
site_bucket_policy = BucketPolicy(
f"BUCKET_POLICY_{data_conf['project_name'].upper()}",
bucket=site_bucket[0].id,
policy=site_bucket_policies_statement.json,
opts=ResourceOptions(depends_on=[site_bucket[0]])
)
I'd appreciate your help π₯Ί pleasedry-keyboard-94795
04/29/2024, 7:37 PMoai
, and the lambda in the apply doesn't return anythingdry-keyboard-94795
04/29/2024, 7:38 PMNone
big-angle-30002
04/29/2024, 7:46 PMdry-keyboard-94795
04/29/2024, 7:47 PMoai = Output.all(...)
, just do Output.all(...)
dry-keyboard-94795
04/29/2024, 7:56 PMget_policy_document
in an `Output.all(...).apply()`call, as it doesn't support Input/Output typesbig-angle-30002
04/29/2024, 7:58 PMbig-angle-30002
04/29/2024, 8:00 PMsite_bucket_policies_statement = get_policy_document(
version="2012-10-17",
statements=[
{
"effect": "Deny",
"principals": [
{
"type": "AWS",
"identifiers": ["*"]
}
],
"actions": ["s3:*"],
"resources": [
site_bucket[0].arn
],
"conditions": [
{
"test": "Bool",
"variable": "aws:SecureTransport",
"values": ["false"]
}
]
},
{
"effect": "Allow",
"actions": ["s3:GetObject"],
"resources": [
site_bucket[0].arn
],
"principals": [{
"type": "AWS",
"identifiers": [ oai.iam_arn ]
}]
},
{
"effect": "Allow",
"actions": [
"s3:PutBucketPolicy",
"s3:GetBucket*",
"s3:List*",
"s3:DeleteObject*"
],
"resources": [
site_bucket[0].arn
],
"principals": [{
"type": "AWS",
"identifiers": [ lambda_role.arn ]
}]
}
]
)
aws:s3:BucketPolicy (BUCKET_POLICY_ARCHIE-STACK):
error: 1 error occurred:
* putting S3 Bucket (bucket-1-archie-stack-nonprod) Policy: operation error S3: PutBucketPolicy, https response error StatusCode: 400, RequestID: ABG1XJX5FZPTS0Y1, HostID: ODRmhKJaygEo69JqTC0ZSAwSD3wBR3EBwskAjF+xh6tZp9MK+3pdIQzQxA2sp+uyRpTmGUCjza2niQptID1gdw==, api error MalformedPolicy: Action does not apply to any resource(s) in statement
dry-keyboard-94795
04/29/2024, 8:06 PMsite_bucket_policies_statement = Output.all(
lambda_role_arn=lambda_role.arn,
site_bucket_arn=site_bucket[0].arn,
oai_iam_arn=oai.iam_arn,
).apply(lambda d: get_policy_document(
version="",
statements=[
{
"effect": "Deny",
"principals": [
{
"type": "AWS",
"identifiers": ["*"]
}
],
"actions": ["s3:*"],
"resources": [
d["site_bucket_arn"],
],
"conditions": [
{
"test": "Bool",
"variable": "aws:SecureTransport",
"values": ["false"]
}
]
},
{
"effect": "Allow",
"actions": ["s3:GetObject"],
"resources": [
d["site_bucket_arn"],
],
"principals": [{
"type": "AWS",
"identifiers": [ d["oai_iam_arn"] ]
}]
},
{
"effect": "Allow",
"actions": [
"s3:PutBucketPolicy",
"s3:GetBucket*",
"s3:List*",
"s3:DeleteObject*"
],
"resources": [
site_bucket[0].arn
],
"principals": [{
"type": "AWS",
"identifiers": [ lambda_role.arn ]
}]
}
],
))
dry-keyboard-94795
04/29/2024, 8:07 PMdry-keyboard-94795
04/29/2024, 8:09 PMaws.iam.GetPolicyDocumentStatementArgs
dry-keyboard-94795
04/29/2024, 8:10 PMstatements=[
aws.iam.GetPolicyDocumentStatementArgs(
resources=[...],
),
]
big-angle-30002
04/29/2024, 8:19 PMbig-angle-30002
04/29/2024, 9:32 PM"Resource": [
f"{args[0]}",
f"{args[0]}/*"
],
and use the verbose input classes for better debug messages xdbig-angle-30002
04/29/2024, 9:35 PM